Can anyone give me a working example of PostbackUrl where both the target page and previous page have masterpage.
For example, let assume I have two pages default1.axpx and default2.aspx. Both of them have a masterpage MyMasterpage.masterpage
I want to postback from default1.aspx to default2.aspx and then extract data from default1 page controls in default2 page.
How can I do that?
You should have titled this question “How do I find a control in a
ContentPlaceholder?”, because your problem is not thatPreviousPagedoesn’t work, it’s that you don’t understand howContentPlaceholders work.This problem has nothing to do with a master page per se, and is entirely related to using a
ContentPlaceholder, which is a Naming Container in asp.net parlance.FindControlsdoes not search inside Naming Containers, which is exactly how they are designed.PreviousPageworks fine with master pages, thus my confusion about what they have to do with your problem. You can access any property on the previous page that you want, and it will in fact work. For example:The problem you are likely encountering is that you’re trying to use
FindControl()to find a specific control in the content page, and it’s not working, precisely because you’re calling FindControl on the PreviousPage, and not on the naming container that the control you’re looking for exists in.To find the control you want, you just have to do a
FindControlon the naming container. The following code works fine, assuming the placeholder is named ContentPlaceHolder1.You can verify that this problem has nothing to do with
PreviousPageby using the following code, which uses only a single page and looks for the control on itself. Place a textbox on your Default.aspx page called TextBox1. Then, in thePage_Loadfunction of the code behind of Default.aspx.cs put this code, then run it in the debugger and step through it.So please, don’t go saying things like “the
PreviousPagedoesn’t work as it should if the pages have masterpage”, because it’s working EXACTLY as it should. The problem is that you don’t know how it should be working. Learn how the page object model works.