Click here to Skip to main content
15,889,281 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionRe: about the project Pin
Paddy Boyd26-Jul-06 0:11
Paddy Boyd26-Jul-06 0:11 
AnswerRe: about the project Pin
SeMartens26-Jul-06 0:34
SeMartens26-Jul-06 0:34 
JokeRe: about the project Pin
mnaveed26-Jul-06 2:38
mnaveed26-Jul-06 2:38 
AnswerRe: about the project Pin
J4amieC26-Jul-06 2:57
J4amieC26-Jul-06 2:57 
QuestionYahoo messenger Library Pin
Mairy25-Jul-06 23:06
Mairy25-Jul-06 23:06 
AnswerRe: Yahoo messenger Library Pin
Ista27-Jul-06 4:20
Ista27-Jul-06 4:20 
QuestionProblem in Redirection Pin
Mairy25-Jul-06 22:56
Mairy25-Jul-06 22:56 
AnswerRe: Problem in Redirection Pin
Vipin Venugopal25-Jul-06 23:29
Vipin Venugopal25-Jul-06 23:29 
Response.Redirect to another form with this URL
Following code snippet shows how it works:
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

This is yet another way to pass values across pages. The typical sequence of steps will be as follows:
§ Create the web form with controls
§ Provide some button or link button that posts the form back
§ In the click event of the button add session variables and set them to control values
§ Response.Redirect to another form
§ In that form access Session variables and remove them if necessary
Following code shows this 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");
}

Using Server.Transfer

This is somewhat complex but sophisticated method of passing values across pages.
The entire process works as follows:
§ Create the web form with controls
§ Create property Get procedures that will return control values
§ Provide some button or link button that posts the form back
§ In the button click event handler call Server.Transfer method that will transfer execution to the specified form
§ In the second form you can get a reference to the first form instance by using Context.Handler property. Then you will use the get properties we created to access the control values.
The code to accomplish this is somewhat complex and is shown below:
Source Web Form
Add following properties to the web form:
public string Name
{
get
{
return TextBox1.Text;
}
}

public string EMail
{
get
{
return TextBox2.Text;
}
}
Now, call Server.Transfer.
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("anotherwebform.aspx");
}
Destination Web Form
private void Page_Load
(object sender, System.EventArgs e)
{
//create instance of source web form
WebForm1 wf1;
//get reference to current handler instance
wf1=(WebForm1)Context.Handler;
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail;
}


Vipin
QuestionPop-up windows in ASP.NET Pin
Mairy25-Jul-06 22:26
Mairy25-Jul-06 22:26 
AnswerRe: Pop-up windows in ASP.NET [modified] Pin
l0kke26-Jul-06 1:43
l0kke26-Jul-06 1:43 
Questionmouseover Pin
rajmani25-Jul-06 21:56
rajmani25-Jul-06 21:56 
AnswerRe: mouseover Pin
alex_-_25-Jul-06 22:48
alex_-_25-Jul-06 22:48 
GeneralRe: mouseover Pin
rajmani25-Jul-06 23:18
rajmani25-Jul-06 23:18 
GeneralRe: mouseover Pin
alex_-_25-Jul-06 23:34
alex_-_25-Jul-06 23:34 
GeneralRe: mouseover Pin
rajmani25-Jul-06 23:57
rajmani25-Jul-06 23:57 
GeneralRe: mouseover Pin
rajmani26-Jul-06 0:18
rajmani26-Jul-06 0:18 
QuestionPaypal Integation in ecommerce site........... Pin
Nagraj Naik25-Jul-06 21:05
Nagraj Naik25-Jul-06 21:05 
AnswerRe: Paypal Integation in ecommerce site........... Pin
Ista4-Aug-06 3:32
Ista4-Aug-06 3:32 
QuestionHandle Event Pin
MHASSANF25-Jul-06 20:10
MHASSANF25-Jul-06 20:10 
AnswerRe: Handle Event Pin
mnaveed26-Jul-06 2:31
mnaveed26-Jul-06 2:31 
AnswerRe: Handle Event Pin
Ista27-Jul-06 4:21
Ista27-Jul-06 4:21 
QuestionOffline Messenger Pin
chaitany25-Jul-06 19:54
chaitany25-Jul-06 19:54 
AnswerRe: Offline Messenger Pin
Paddy Boyd25-Jul-06 22:23
Paddy Boyd25-Jul-06 22:23 
QuestionGridview rowspan Pin
silverfox_118825-Jul-06 19:44
silverfox_118825-Jul-06 19:44 
AnswerRe: Gridview rowspan Pin
silverfox_118825-Jul-06 19:47
silverfox_118825-Jul-06 19:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.