Wednesday, January 21, 2009

Use CrossPagePostBack Property to Transform Parameter From one Page to Another

In the Begining Add two web form Source.aspx and Destination.aspx

Drag three Control on to the Source.aspx Page

TextBox, Calendar and Button
Then Paste the following code on to the button click Event

protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("Default2.aspx");
}

Then Drag the Label Control on to the Destination.aspx Page

Then Paste the following code on to the Page_Load Event

protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
TextBox pp_TextBox1;
Calendar pp_Calendar1;
pp_TextBox1 = (TextBox)PreviousPage.FindControl("TextBox1");
pp_Calendar1 = (Calendar)PreviousPage.FindControl("Calendar1");
Label1.Text = "Hello " + pp_TextBox1.Text + "
" + "Date Selected " + pp_Calendar1.SelectedDate.ToShortDateString();
}
else
Label1.Text = "Sorry";
}
Then run the following code write something in a Textbox and select the date from the Calendar then press the button you will see that all of these data would be transfered on to the Next Page

No comments:

Post a Comment