Labels

Wednesday, July 4, 2007

PreviousPageType

Here is a type-safe approach in case of Server.Transfer as well. [Similar to the specified '<%@ PreviousPageType VirtualPath="Default.aspx" %> ' approach].

 

i.e For the below case, there is again a type-safe approach.

 

On Page2.aspx:

if (Request.Form ["TextBox1"] != "" )

Label1.Text = Request.Form["TextBox1"];

 

Modify the 'Default.aspx' page as:

 

1.    '<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" ClassName="_Default" %>'

 

Modify the 'Redirect.aspx' page as:

 

2.    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Redirect.aspx.cs" Inherits="Redirect" %>

3.    <%@ Reference Page="~/Default.aspx" %>

 

Modify the 'Redirect.aspx'.cs' as:

 

4.    _Default prevPage = Context.Handler as _Default;

5.     Label1.Text= prevPage.PrevText;

 

Hope it helps.

 

Traditional way to achieve the cross page posting:

Lest assume that you are moving to Page2.aspx from Page1.aspx using Response.redirect and you want to access few or all the controls on Page1.aspx.

In general scenario you will use the Sessions to do this. But there is a better option:

Following is the code for button on Page1.aspx:

<asp:button id="Button1" text="Go to Page2 " postbackurl=" Page2.aspx" runat="Server"> </asp:button>

And on Page2.aspx:

text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;

 

That's it. In this way you can use any control on the previous page.

 

Yet another way to achieve this:

On Page1.aspx on button click:

protected void Button1_Click(object sender, EventArgs e)

{

        Server.Transfer("Page2.aspx",true);

}

 

On Page2.aspx:

if (Request.Form ["TextBox1"] != "" )

Label1.Text = Request.Form["TextBox1"];

 

 

Thanks & Regards,

Arun Manglick

SMTS || Microsoft Technology Practice || Bridgestone - Tyre Link || Persistent Systems || 3023-6258

 

DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.

No comments:

Post a Comment