The successor of ASP.NET is ASP.NET Core. It is a re-integration of ASP.NET as a web framework, along with other frameworks.dot net traning
ASP.NET web forms give excellent event driven programming model to developers. It simplifies the overall design of your application but has some problems of its own. For example, in conventional ASP values can be easily passed from one ASP page to another ASP page using POST. The same thing is impossible in ASP.NET if you want to stick to web form model .There are some ways that can be used to overcome this situation. This article denotes various possibilities to do the same.
Specifically we will deal how to pass values using querystring, how to utilise session variables to do the same and finally how to use Server.Transfer method.
Querystring
Querystring is a day old process to pass values across pages. The main advantage of this method is very simple. What limits is that the values are visible in the browser address bar and you can not pass objects that way. This method is best suited when you want to pass less number of values that need not be secured from others. In order to put this method you need to follow these steps:
Develop the web form with controls
Give some button that posts the form again
In the event of clicking the button design a string that holds URL for another
Add control values to the URL as querystring parameters
Response.Redirect to another form with this URL
Here is the code:
Source Web Form
private void Button1_Click
(object sender, System.EventArgs e)
{
string url;
url=”anotherwebform.aspx?name=” +
TextBox1.Text + “&email=” +
TextBox2.Text;
Response.Redirect(url);
}
Destination Web Form
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Request.QueryString["name"];
Label2.Text=Request.QueryString["email"];
}
Using Session variables
Another way to pass values across pages. Here you store control values in session variables and reach out for them in another web form. But storing too much data in a session can be an overhead on the server. It also needs some kind of cleaning action from your side so that unwanted session variables are deleted The sequence of steps are as follows:
Develop the web form with controls
Give some link button that posts the form back
Add session variables and set them to control values
Response.Redirect to another form
In that form ingress Session variables and delete them if necessary
Here the code shows in action:
Source Web Form
private void Button1_Click
(object sender, System.EventArgs e)
{
//textbox1 and textbox2 are webform
//controls
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Server.Transfer(“anotherwebform.aspx”);
}
Destination Web Form
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove(“name”);
Session.Remove(“email”);
}