locked
data store for moving from page to page RRS feed

  • Question

  • User811628830 posted

    Hello,

    I'm trying to build a website.  And I'm wondering what the best way to hold the users information would be prior to them going to the register page.  So for example:

    Front page

    What kind of house do you live in? ...Textbox1

    How many rooms does it have?....Textbox2

    Submit button<click>

    Next Page

    progress bar searching for records..

    Next page

    Your house & rooms were not found, however we encourage you to <hyperlink>register<hyperlink> click

    Register Page

    asp createuserwizard etc etc....

    Soooooo....Do I use the users IP address or what unique way is there to hold their start information from the textboxes they have already entered so that I can add them to a new database table that I make in the database?  Or do I put all of their information as a temp table?  Or does it have something to do with cookies? 

    Thanks

    George

    Sunday, December 18, 2016 4:13 AM

All replies

  • User2103319870 posted

    If you want to move data from one page to another , then There are mutliple ways you can acheive this functionality

    1) Using Form

    When the source page uses the HTTP POST action to navigate to the target page, you can retrieve posted values from the Form collection in the target page. 

    This basically involves two steps

    1. In the source page, include a form element that contains HTML elements (such as input or textarea) or ASP.NET server controls (such as TextBox orDropDownList controls) that post values when the form is submitted.

    2. In the target page, read the Form collection, which returns a dictionary of name/value pairs, one pair for each posted value.

    Please try with the below implementaion

    Your PageA.aspx

    <form id="form2" runat="server">
         <asp:TextBox ID="EmployeeName" runat="server"></asp:TextBox>
         <!-- Add Your Other controls here -->
         <asp:Button ID="btnSubmit" runat="server" Text="Submit" PostBackUrl="YourPageB.aspx" />
    </form>

    You can access the posted values using Request.Form in your PageB.Aspx

    Your PageB.Aspx

     //Grab the value passed from YourPageA.aspx
                String Passedvalue = Request.Form["EmployeeName"];

    2) Using Session

    An Easy solution is to use session and it will be like this

    Your PageA.aspx

    //Set the value of Textbox to session
                Session["Data"] = Textbox1.Text;
                //Perform your Redirect
                Response.Redirect("YourPageB.aspx");

    YourPageB.aspx(Receiver Page)

    You can read values from session like given below

                if (!String.IsNullOrEmpty(Session["Data"].ToString()))
                {
    
                    //Read values from session
                    string valueA = Session["Data"].ToString();
    
                }

    3) Another suggestion is to use QueryString

    Please see the sample implemenation

    Your PageA.aspx

    You can pass value to pageB like given below

     protected void btnRedirect_Click(object sender, EventArgs e)
            {
                //Pass the value from Textbox as Query string
                Response.Redirect("YourPageB.aspx?PassingValue=" + Server.UrlEncode(Textbox1.Text));
            }

    YourPageB.aspx(Receiver Page)
    You can read the value passed through query string like given below

      //Read the values from Query string
                string value = Request.QueryString["PassingValue"].ToString();

    You can get more details in the below link

    Sunday, December 18, 2016 7:15 AM