ASP.NET: Access Controls after using PostBackUrl

Whenever you execute a Cross Page Post-Back from one site to another by using

<asp:button PostBackUrl=“anotherpage.aspx" runat=“server"/>

be sure to set this on anotherpage.aspx to gain full access to the controls of the previous page:

<%@ PreviousPage VirtualPath=“previouspage.aspx" %>

Afer that, you can access the controls by using the Page.PreviousPage Property.

Example:

Textbox MyNewTextBox = PreviousPage.FindControl("PreviousPageTextBox");
Label1.Text = MyNewTextBox.Text;

Cheers!

5 comments ↓

#1 Kevin on 08.30.06 at 7:49 pm

I added this and I see “Parser Error Message: The directive ‘previouspage’ is unknown.”. Is there something else required for this directive to work?

#2 andreas.kraus on 08.30.06 at 7:56 pm

Hi Kevin, please show me your complete code.

#3 Treck on 09.04.06 at 12:20 pm

Working great Andreas, thanks for the tipp!

#4 @Kevin on 05.14.10 at 2:58 pm

PreviousPageType not PreviousPage

#5 bhagwat on 07.05.11 at 11:02 am

hi all coder..i m using
RadioButton rd = (RadioButton)PreviousPage.FindControl(“RadioButton3”);// (RadioButton)Panel1.PreviousPage.FindControl(“RadioButton3”) as RadioButton;
if (rd.Checked == true)
{
Reset.Visible = false;
}

error object can not find instance of an object ..pls tell me solution thanxx

Leave a Comment