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!

3 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!

Leave a Comment