Need help using PostBackURL
-
hi friends, I'm trying an example on PostBackURL.My application has two pages,page1.aspx & page2.aspx. On page1,I've a textbox & a calendar with 2 button controls.I'm trying to display the selected contents on Page1 into a label on Page2.Here's what my code on Page1.aspx looks like Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Label1.Text = "Hello " & TextBox1.Text & "
" & _ "Date Selected: " & Calendar1.SelectedDate.ToShortDateString() End SubOn Page2.aspx, I've included a virtual path to reference page1 & Code on page2.aspx is: Protected Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) lblDisplay.Text = "Hello" & PreviousPage.pp_TextBox1.Text & "
" & _ "Date Selected: " & _ PreviousPage.pp_Calendar1.SelectedDate.ToShortDateString() End Sub I'm not getting any errors & neither am i getting any display on Page2.aspx. can anyone please help me find the solution ? Thanks a lot in advance.. -
hi friends, I'm trying an example on PostBackURL.My application has two pages,page1.aspx & page2.aspx. On page1,I've a textbox & a calendar with 2 button controls.I'm trying to display the selected contents on Page1 into a label on Page2.Here's what my code on Page1.aspx looks like Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Label1.Text = "Hello " & TextBox1.Text & "
" & _ "Date Selected: " & Calendar1.SelectedDate.ToShortDateString() End SubOn Page2.aspx, I've included a virtual path to reference page1 & Code on page2.aspx is: Protected Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) lblDisplay.Text = "Hello" & PreviousPage.pp_TextBox1.Text & "
" & _ "Date Selected: " & _ PreviousPage.pp_Calendar1.SelectedDate.ToShortDateString() End Sub I'm not getting any errors & neither am i getting any display on Page2.aspx. can anyone please help me find the solution ? Thanks a lot in advance..the easiest way is using response.redirect option On page 1 string text1 = TextBox1.Text; string text2 = Calendar1.SelectedDate.ToShortDateString(); response.redirect("page2.aspx?message1=" +text1+",message2=" +text2 ,true); On page 2 string ms1 = Request.QueryString["message1"]; string ms2 = Request.QueryString["message2"]; Its on C#
keep Learning and you never will be out of date...
-
hi friends, I'm trying an example on PostBackURL.My application has two pages,page1.aspx & page2.aspx. On page1,I've a textbox & a calendar with 2 button controls.I'm trying to display the selected contents on Page1 into a label on Page2.Here's what my code on Page1.aspx looks like Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Label1.Text = "Hello " & TextBox1.Text & "
" & _ "Date Selected: " & Calendar1.SelectedDate.ToShortDateString() End SubOn Page2.aspx, I've included a virtual path to reference page1 & Code on page2.aspx is: Protected Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) lblDisplay.Text = "Hello" & PreviousPage.pp_TextBox1.Text & "
" & _ "Date Selected: " & _ PreviousPage.pp_Calendar1.SelectedDate.ToShortDateString() End Sub I'm not getting any errors & neither am i getting any display on Page2.aspx. can anyone please help me find the solution ? Thanks a lot in advance..How do you define properties pp_TextBox1 and pp_Calendar1? Can you see the TextBox and Calender controls with the selected values in the PreviousPage when you step through your code? Another option to get reference to the controls of the Page1 is to use the FindControl method.
-
the easiest way is using response.redirect option On page 1 string text1 = TextBox1.Text; string text2 = Calendar1.SelectedDate.ToShortDateString(); response.redirect("page2.aspx?message1=" +text1+",message2=" +text2 ,true); On page 2 string ms1 = Request.QueryString["message1"]; string ms2 = Request.QueryString["message2"]; Its on C#
keep Learning and you never will be out of date...
hi Britney, I tried this piece of code but still I'm not able to display the contents of textbox & the selected calendar date onto a label on page2.I've written the response.redirect code in a Button2_Click Sub. The control is transferred from page1 to page2 and the page2 url will carry the contents of strings message1 & message2, but they are not being displayed onto the label.Can you please tell me where I'm going wrong ??? thanks a lot for your help.
-
How do you define properties pp_TextBox1 and pp_Calendar1? Can you see the TextBox and Calender controls with the selected values in the PreviousPage when you step through your code? Another option to get reference to the controls of the Page1 is to use the FindControl method.
pp_TextBox1 and pp_Calendar1 are the property procedures that I've written to retireve the values from TextBox & selected date on Calendar.I've two buttons on Page1. When I click on Button1, the contents of TextBox & selected Calendar date are displayed onto the same page on a label.I'm able to get this .When I click on Button2, I want to transfer the contents of TextBox and Calendar control to a label on Page2. When I click the Button2, the Page2.aspx form is loaded but I dont see any display on the label... I'm working this example from Professional ASP.Net 2.0 book by wrox publications.They have given an example using FindControl method but I didn't get any output on Page2.aspx even then..So, please tell me where I'm going wrong ??? Thanks in advance..
-
hi Britney, I tried this piece of code but still I'm not able to display the contents of textbox & the selected calendar date onto a label on page2.I've written the response.redirect code in a Button2_Click Sub. The control is transferred from page1 to page2 and the page2 url will carry the contents of strings message1 & message2, but they are not being displayed onto the label.Can you please tell me where I'm going wrong ??? thanks a lot for your help.
page1.aspx Five Controls TextBox1 Calendar1 Button1 Button2 Label1 codeBehind for page1.aspx
public partial class page1 : System.Web.UI.Page { string text1 = ""; string text2 = ""; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { text1 = TextBox1.Text; text2 = Calendar1.SelectedDate.ToShortDateString(); Label1.Text = text1 + text2; } protected void Button2_Click(object sender, EventArgs e) { text1 = TextBox1.Text; text2 = Calendar1.SelectedDate.ToShortDateString(); Response.Redirect("page2.aspx?message1="+text1+"&message2="+text2 ,true); } }
Page2.aspx Two Controls Label1 Button1 code behind for page2.aspxpublic partial class page2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string ms1 = Request.QueryString["message1"].ToString(); string ms2 = Request.QueryString["message2"].ToString(); Label1.Text = ms1 + ms2; } }
I hope this explication be good for you ;)keep Learning and you never will be out of date...
-
page1.aspx Five Controls TextBox1 Calendar1 Button1 Button2 Label1 codeBehind for page1.aspx
public partial class page1 : System.Web.UI.Page { string text1 = ""; string text2 = ""; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { text1 = TextBox1.Text; text2 = Calendar1.SelectedDate.ToShortDateString(); Label1.Text = text1 + text2; } protected void Button2_Click(object sender, EventArgs e) { text1 = TextBox1.Text; text2 = Calendar1.SelectedDate.ToShortDateString(); Response.Redirect("page2.aspx?message1="+text1+"&message2="+text2 ,true); } }
Page2.aspx Two Controls Label1 Button1 code behind for page2.aspxpublic partial class page2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string ms1 = Request.QueryString["message1"].ToString(); string ms2 = Request.QueryString["message2"].ToString(); Label1.Text = ms1 + ms2; } }
I hope this explication be good for you ;)keep Learning and you never will be out of date...
hi Britney, I got it... Thanks a ton really.. have been stuck with this problem for a few days now... thanks again..
-
pp_TextBox1 and pp_Calendar1 are the property procedures that I've written to retireve the values from TextBox & selected date on Calendar.I've two buttons on Page1. When I click on Button1, the contents of TextBox & selected Calendar date are displayed onto the same page on a label.I'm able to get this .When I click on Button2, I want to transfer the contents of TextBox and Calendar control to a label on Page2. When I click the Button2, the Page2.aspx form is loaded but I dont see any display on the label... I'm working this example from Professional ASP.Net 2.0 book by wrox publications.They have given an example using FindControl method but I didn't get any output on Page2.aspx even then..So, please tell me where I'm going wrong ??? Thanks in advance..
-
You can see the sample code in MSDN: Cross-Page Posting in ASP.NET Web Pages [^]
Thank you. will surely look into that. Thanks