Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a webform1.aspx, which contains 100 Textboxes . I have to pass these 100 textbox values to webform2.aspx.

Please help me which is the best way to to pass values from one page to another.

Apart from Session is any other best technique..
Posted
Updated 30-Nov-14 20:41pm
v2
Comments
Kornfeld Eliyahu Peter 1-Dec-14 1:30am    
If you had - let say - 10 text-boxes, could you solve the problem?
syed shanu 1-Dec-14 1:39am    
You can create a array and i hope for example you have placed all your controls in panel or in div or etc in Button click of form1 get all textbox value and store it in string array. Finally set the array to session. In next page from session get the Array value and set all the values to corresponding textbox.
Jignesh Khant 1-Dec-14 1:40am    
Sessions or query strings.
Praveen Kumar Upadhyay 1-Dec-14 3:03am    
This is very easy in MVC, you don't need to pass the individual fields.

There are many ways you can do it but since you have large number of textboxes you can set the values in an array and assign the array to a session.
Also please have a look at the other ways you can do it :
----------------------------------------------------------------------------

Using Session State or Application Variable :

Using this technique I will store the data in session variable on the client machine and on the next page will grab it. Using Application Variable instead of Session Variable is recommend by experts.

ASPX Page:

<asp:textbox id="txtData" runat="server" xmlns:asp="#unknown">



<asp:button id="btnSessionState" runat="server" text="Session State" onclick="btnSessionState_Click" xmlns:asp="#unknown">

Code-Behind:

protected void btnSessionState_Click(object sender, EventArgs e)
{
Session["Data"] = txtData.Text;
Response.Redirect("SessionState.aspx");
}

Receiver ASPX Page:


Session State


Data is: <%=Session["Data"] %>
And you all set, run it test it.

Using Query String

Using this technique I will add my data with URL and on the next page will grab it.

ASPX Page:

<asp:textbox id="txtData" runat="server" xmlns:asp="#unknown">



<asp:button id="btnQueryString" runat="server" text="Query String" onclick="btnQueryString_Click" xmlns:asp="#unknown">

Code-Behind:

protected void btnQueryString_Click(object sender, EventArgs e)
{
Response.Redirect("QueryString.aspx?Data=" + Server.UrlEncode(txtData.Text));
}

Receiver ASPX Page:

Query String


Data is: <%=Server.UrlDecode(Request.QueryString["Data"]) %>
And you all set, run it test it.

Using HttpPost

Using this technique I will call a post back url and the on next page using Request.From I will grab it.

ASPX Page:

<asp:textbox id="txtData" runat="server" xmlns:asp="#unknown">



<asp:button id="btnHttpPost" runat="server" text="HTTPPost" postbackurl="~/HttpPost.aspx" xmlns:asp="#unknown">

Note: There is no any code-behind method call instead of a postbackurl in button attribute.

Receiver ASPX Page:

HttpPost


Data is: <%=Request.Form["txtData"] %>

And you all set, run it test it.

Using Public Properties

Using this technique I will send the using a public method and on the next page will grab it using PreviousPage.MethodName.

ASPX Page:

<asp:textbox id="txtData" runat="server" xmlns:asp="#unknown">



<asp:button id="btnPublicProperties" runat="server" text="Public Properties" onclick="btnPublicProperties_Click" xmlns:asp="#unknown">

Code-Behind:

protected void btnPublicProperties_Click(object sender, EventArgs e)
{
Server.Transfer("PublicProperties.aspx");
}
public string PublicData
{
get
{
return txtData.Text;
}
}

Receiver ASPX Page:

Public Properties


Data is: <%=PreviousPage.PublicData %> :
 
Share this answer
 
1) if u redirect from webform1 to Webform2 direct
then use Server.transfer

on webform2 suppose
TextBox t1=(TextBox)Page.PreviousPage.FindControl("ur textbox name on webform1");

2)If u want to use this on several page in application
then create one class assign textbox value to this class member and store that object in session and use it on several pages
 
Share this answer
 
Comments
Mukesh Pr@sad 1-Dec-14 2:22am    
But server.transfer does not updates the url ,so when user will perform postback on navigated page it will again redirect to previous webform, so its not a good idea to use server.transfer.
Abid Shk 1-Dec-14 2:28am    
if u dont want to use server.transfer then use postbackUrl on button property
my code also work with postback url
otherwise use response.redirect
First of all, 100 TextBoxes on one Page is not a good idea. You should think of reducing it and breaking it to multiple pages or implement some wizard. It is also not good if you consider User Experience.

Refer the link to know more on how to transfer data between pages. - How to: Pass Values Between ASP.NET Web Pages[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900