populate textbox on 2nd page with user input on 1st

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mlg74
    New Member
    • Mar 2007
    • 13

    populate textbox on 2nd page with user input on 1st

    I am desiging a web app using visual web developer and sql express 2005. Language is VB.

    My default page has a form with only 2 form fields, which on submit goes to my default2 page, which has a form, where I am using panels to break it up into parts.

    On the default page, one of the two fields is a textbox for zip code. On the very next page (default2) is a registration page, asking for address, and it has zip code as well. I do not want my users to have to enter the zip code twice, so how do I get the zip code entered on the default page populated on the 2nd page?

    I've tried session variables, cross page postback, and query strings, but have had no succes with any and do not fully understand the part where it populates the textbox, so I'm out of clues.

    Any help would be appreciated.
  • acnx
    New Member
    • Mar 2007
    • 4

    #2
    Cross page postback is the way I would do it.

    default1.aspx
    <asp:textbox ID="Zip" runat="server" />
    <asp:button runat='server" postbackurl="de fault2.aspx" />

    default2.aspx
    <asp:textbox ID="Zip" runat="server" />

    default2.aspx.c s
    in page load
    Zip.Text = Request.Form["Zip"].ToString();


    Hope this helps

    Originally posted by mlg74
    I am desiging a web app using visual web developer and sql express 2005. Language is VB.

    My default page has a form with only 2 form fields, which on submit goes to my default2 page, which has a form, where I am using panels to break it up into parts.

    On the default page, one of the two fields is a textbox for zip code. On the very next page (default2) is a registration page, asking for address, and it has zip code as well. I do not want my users to have to enter the zip code twice, so how do I get the zip code entered on the default page populated on the 2nd page?

    I've tried session variables, cross page postback, and query strings, but have had no succes with any and do not fully understand the part where it populates the textbox, so I'm out of clues.

    Any help would be appreciated.

    Comment

    • mlg74
      New Member
      • Mar 2007
      • 13

      #3
      Thankyou for you help.

      When I type:

      Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

      PostalCode.Text = Request.Form["PostalCode "].ToString()

      End Sub

      "Request.Fo rm" is underlined and the message it give is "cannot be converted to string."

      And, if I change the brackets around postalcode to parentheses (dont ask why I did that), such as: "PostalCode.Tex t = Request.Form("P ostalCode").ToS tring(), the previous error goes away, but a new error which says "Object reference not set to an instance of an object."

      Also, if I put a semicolon at the end of the line, like in your example, it says "character not valid."

      This is as close as I've come to getting this thing work, so I'm thankful for your help.

      Comment

      • mlg74
        New Member
        • Mar 2007
        • 13

        #4
        Oh, does the "cs" in default2.aspx.c s stand for C#? Because I as using Visual Basic.

        Comment

        • acnx
          New Member
          • Mar 2007
          • 4

          #5
          Sorry, it was c#

          I don't do VB. though this should work

          Zip.Text = Request.Form("Z ip").ToString ()

          Note above needs to be in Page_Load(ByVal sender....

          Comment

          • channaJ
            New Member
            • Mar 2007
            • 67

            #6
            Originally posted by mlg74
            Oh, does the "cs" in default2.aspx.c s stand for C#? Because I as using Visual Basic.
            Yes. ".cs" is the extention for C# files. If you are using VB here, your code behind would be with the extention ".vb"

            The other case is in VB you do not have to put a semi colon at the end of the statement.

            Comment

            • nmsreddi
              Contributor
              • Jul 2006
              • 366

              #7
              Hello

              if you dont wnat to go for sessions there are other alternatives you can use

              one simple logic is if you want to access only zipcode (only one or two

              variables ) then you can pass them as query string values while navigating to

              the second form and catch those values by using Request object.and assign

              that value to the textbox in form2.

              //form2 textbox.text=Re quest["zipcode"];

              I hope this may solve your problem .

              Comment

              • mlg74
                New Member
                • Mar 2007
                • 13

                #8
                When I run my app, I still get the error: Re: Error "Object reference not set to an instance of an object" Regarding the line: PostalCode.Text = Request.Form("P ostalCode").ToS tring()

                Any ideas?

                Comment

                • mlg74
                  New Member
                  • Mar 2007
                  • 13

                  #9
                  Do you think its because the default and default2 pages utilize master pages?

                  Comment

                  • acnx
                    New Member
                    • Mar 2007
                    • 4

                    #10
                    Originally posted by mlg74
                    Do you think its because the default and default2 pages utilize master pages?
                    yeah that will do it!

                    You are best using findcontrol

                    this will do the trick

                    Code:
                    Dim ctl As TextBox = Nothing 
                    If Not Page.PreviousPage Is Nothing Then 
                           ctl = CType(PreviousPage.Form.FindControl("ContentPlaceHolder1").FindControl("Zip"), TextBox) 
                           If Not ctl Is Nothing Then
                               Zip.Text = ctl.Text
                           End If
                    End If

                    Comment

                    • mlg74
                      New Member
                      • Mar 2007
                      • 13

                      #11
                      Thank you! That worked perfectly! It didn't work at first when i tried it yesterday, but it worked today. Must have been a typo on my part.

                      Thanks again...

                      Comment

                      Working...