Explanation:
One of the potential drawbacks to using cross page posting in ASP.NET 2.0 is that the previous page is allocated and executed through its LoadComplete event so that the target page can look at all of the re-hydrated state of the controls in the previous page to retrieve the values posted by the client.
For some reason, it never occurred to me that you don't even need to use the PreviousPage property in the target page to retrieve the values, you can simply extract the name/value pairs from the POST body directly (just as you would in classic ASP or even straight HTML).
This Article is based on the question asked in ASP .NET Forum by Swati+Jain the thread link is http://forums.asp.net/thread/1508099.aspx
now let us see what our pages look like;
This is "FirstPage.aspx"
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" Height="183px" Width="185px">asp:ListBox>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />div>
form>
Now "SecoundPage.aspx"
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtStartDate" runat="server">asp:TextBox>
<br />
<asp:TextBox ID="txtEndDate" runat="server">asp:TextBox>
<br />
<asp:Button ID="btnGod" runat="server" Text="Go" PostBackUrl="~/firstPage.aspx" Width="61px" />
div>
form>
Let us see how does code behind look like for "FirstPage.aspx"
protected void Page_Load(object sender, EventArgs e)
{
string str1 = Request["txtStartDate"] + Request["txtEndDate"];
ListBox1.Items.Add(str1);
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("secoundPage.aspx");
}
Request["txtStartDate"] is the way you can access the string Property of a TextBox.
The potential advantage of this technique is that the PreviousPage property of the Page class allocates and executes the prior page on demand, so if you never access the PreviousPage property, it will never allocate and execute the previous page at all! You don't have to worry about spending extra time processing a page that won't actually render, and you don't have to worry about instrumenting your source page's logic with conditionals using IsCrossPagePostBack to avoid executing code during the cross page post evaluation.
One caveat to this technique is that you must use the actual POST body name of the input element to extract the value, which may be different from the simple ID attribute of the control if it is embedded in another control. You can always just look at the rendered page to discover what this is, or you can use the ClientID attribute of any control to find it programmatically.
Hope it help.
|