Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 25th, 2008, 12:39 PM
Registered User
 
Join Date: Jul 2008
Location: Phoenix, AZ, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing FormView fields

I am a newbie. I am writing my first ASP.NET 3.5 form in VB.
Does anyone know how to refer to the fields inside a FormView control that is in read only mode? I have a SQL DB this control is pulling two fields from, firstname and lastname. I can't seem to find the syntax to get that data from the FormView to be able to use in a querystring to pass to the next page in the Code Behind of the Submit button.

  #2 (permalink)  
Old July 25th, 2008, 02:20 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

use findcontrol....

Let's assume that your First and Last Names are in Labels in the FormView you can do
something like:

Dim FirstName As String = CType(FormView1.FindControl("FirstNameLabel"), Label).Text
Dim LastName As String = CType(FormView1.FindControl("LastNameLabel"), Label).Text

Now you have the first and last name in Variables that you can do anything with you would like.

Jason Hall
  #3 (permalink)  
Old July 25th, 2008, 02:27 PM
Registered User
 
Join Date: Jul 2008
Location: Phoenix, AZ, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much for the reply. Now, if I wanted to use a Response.Redirect command to pass these variable to the next page, how would that syntax go?
  #4 (permalink)  
Old July 25th, 2008, 02:32 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

easy...

Response.Redirect("~/Page.aspx?FN=" & FirstName & "&LN=" & LastName)

This isn't homework or something is it? I don't mind helping but can't ask us to do it for you.

Jason Hall
  #5 (permalink)  
Old July 25th, 2008, 02:39 PM
Registered User
 
Join Date: Jul 2008
Location: Phoenix, AZ, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again.
No, not homework. I am desperately trying to learn ASP.NET and VB in order to save my company money by developing our own webforms and not going to school (don't have the time, anyway). I've read several of the Teach Yourself books, but need to fill in the gaps. I am very grateful for your help. On the Code Behind for the 2nd page, what would the syntax be to grab the query string data and post them to a label?

  #6 (permalink)  
Old July 25th, 2008, 02:43 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

ok i know where your coming from i did the same thing so i'll be GLAD to help....

on the Page_Load (or any other event i guess) you would use

Dim FirstName As String = Request.QueryString("FN").ToString
Dim LastName As String = Request.QueryString("LN").ToString

now you have them in variable form to do what you like with in the code behind.

Jason Hall
  #7 (permalink)  
Old July 25th, 2008, 02:50 PM
Registered User
 
Join Date: Jul 2008
Location: Phoenix, AZ, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much Jason. I'd don't feel so alone on this. Last two things:

If I have a label on the "Thank You for registering" page (the 2nd page that is being passed the two fields in the querystring) how do I assign it the value of either the new FirstName or LastName variables? See label control below.

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Lastly, what do you recommend that someone do to proceed in learning to be proficient in ASP.NET 3.5 and VB? Any suggestions would be greatly appreciated.

  #8 (permalink)  
Old July 25th, 2008, 02:56 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

all you need to do is set the text value of the label to equal the variables...

Label1.Text = FirstName & " " & LastName

(notice i put a space between the first and last name " ")

What i recommend is just dive into it, learn the fundamentals and keep practicing (Everyday would be great) as often as you can. Look on these forums at other people's issues as you might learn something. When you need help supply as much code as relates to your issue that way it doesn't look like you are asking for people to do it for you, This also lets them critique what you have done and may offer a simpler/better way to do. Also don't take offense to what people say about your code because "Programmers" tell it like it is, but, they are always willing to help. So just soak in as much as you can if this is what you really want to do.

Jason Hall
  #9 (permalink)  
Old July 25th, 2008, 04:27 PM
Registered User
 
Join Date: Jul 2008
Location: Phoenix, AZ, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much Jason.
If you have a chance, I need to figure out how to see if an ID is alread registered in my table and if so, to stop the INSERT and display an error. Right now my app crashes on duplicates. Here is my code for the DB call Sub:

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim strConnectionString As String = ("server=SOLOMONSQL;Initial Catalog=RETracker;Persist Security Info=True;User ID=SA;Password=sa")
        Dim Conn As New SqlConnection(strConnectionString)
        Dim strSQL As String = "INSERT INTO tbl10K_Registrations (ID, Office, Mobile_Phone, Email_Address, Attending, Rep_Fname, Rep_Lname, Rep_Phone, Rep_Email) VALUES ('" + txtAdcode.Text + "', '" + txtOffice.Text + "', '" + txtMobile.Text + "', '" + txtEmail.Text + "', '" + RadioButtonList1.SelectedValue + "', '" + Rep_Fname.Text + "', '" + Rep_Lname.Text + "', '" + Rep_Phone.Text + "', '" + Rep_Email.Text + "')"
        Dim objCmd As New SqlCommand(strSQL, Conn)
        Conn.Open()
        objCmd.ExecuteNonQuery()
        Conn.Close()
        Dim FirstName As String = CType(FormView1.FindControl("AgentFirstNameLabel") , Label).Text
        Dim LastName As String = CType(FormView1.FindControl("AgentLastNameLabel"), Label).Text
        Response.Redirect("ThankYou.aspx?FN=" & FirstName & "&LN=" & LastName)
    End Sub

  #10 (permalink)  
Old July 26th, 2008, 12:32 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

Ok sorry about taking so long.

What you can do is use an Exists statement in your SQL query:

"If Not Exists(Select ID from tbl10K_Registrations where ID='" & txtAdcode.Text & "') INSERT INTO tbl10K_Registrations (ID, Office, Mobile_Phone, Email_Address, Attending, Rep_Fname, Rep_Lname, Rep_Phone, Rep_Email) VALUES ('" + txtAdcode.Text + "', '" + txtOffice.Text + "', '" + txtMobile.Text + "', '" + txtEmail.Text + "', '" + RadioButtonList1.SelectedValue + "', '" + Rep_Fname.Text + "', '" + Rep_Lname.Text + "', '" + Rep_Phone.Text + "', '" + Rep_Email.Text + "')"

Jason Hall
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
formview mcarol44 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 January 5th, 2008 06:44 AM
Inserting in two formview shahzadgodil ASP.NET 2.0 Professional 2 October 18th, 2006 11:33 AM
Accessing Controls in FormView cryspe ASP.NET 2.0 Basics 0 May 16th, 2006 03:59 PM
accessing fields in a subform Hudson40 Access VBA 8 March 25th, 2005 06:15 AM
Using Forum fields select fields on the fly hellosureshkumar Crystal Reports 0 December 17th, 2004 08:20 AM



All times are GMT -4. The time now is 02:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.