How to get info from PreviousPage

A

Alan Silver

Hello,

I'm doing a cross page post, and want to pick up information from the
previous page. The problem is that the previous page contains a user
control that is loaded into a Placeholder at run time. I can't seem to
get at the Placeholder from the target page.

The first page has an empty placeholder, and the code-behind loads a
user control dynamically and adds it to the placeholder. The user
control grabs an ID from the querystring (hidden by using URL rewriting)
and adds HTML to the control itself.

On (cross page) posting, the target page does the following...

if (PreviousPage != null) {
PlaceHolder plcProductDetails =
(PlaceHolder)PreviousPage.FindControl("plcProductDetails"); }

but this always comes out null. Any ideas? Thanks for any help.
 
A

Alan Silver

Alan Silver said:
Hello,

I'm doing a cross page post, and want to pick up information from the
previous page. The problem is that the previous page contains a user
control that is loaded into a Placeholder at run time. I can't seem to
get at the Placeholder from the target page.

The first page has an empty placeholder, and the code-behind loads a
user control dynamically and adds it to the placeholder. The user
control grabs an ID from the querystring (hidden by using URL rewriting)
and adds HTML to the control itself.

On (cross page) posting, the target page does the following...

if (PreviousPage != null) {
PlaceHolder plcProductDetails =
(PlaceHolder)PreviousPage.FindControl("plcProductDetails"); }

but this always comes out null. Any ideas? Thanks for any help.

It occurred to me after posting that the placeholder is inside a content
control as this is on a master page. Presumably I have to find a way of
getting the content control, then getting the placeholder from within
it, then getting the user control from within that, then getting the
properties I want from the user control.

Is there a simple way to do this, or do I have to work my way down, and
hope that I don't change the names or positions of any of these controls
in the future?

TIA
 
A

Alan Silver

Alan Silver said:
Is there a simple way to do this, or do I have to work my way down, and
hope that I don't change the names or positions of any of these
controls in the future?

OK, having played around with this, I have realised that trying to work
my way down is going to be impossible. I don't know the IDs of the
controls as each container changes the IDs of its child controls, and
due to the way master pages, child pages, content holders, place
holders, custom controls, etc are set up, the hierarchy becomes very
complex. The slightest change in the HTML would throw the entire thing
out, causing me to have to rewrite the code all over again.

So, is there some direct way of getting at a control in the custom
control? I can't believe MS added this great feature, and didn't give
some reliable way of getting at controls in the previous page.

Any help mucho appreciated.
 
A

Alan Silver

Scott Allen said:
Alan:

I wrote an article on cross page postbacks where I have the page
implment an interface and expose a property with the paramter (or the
control) I need to get to. It makes the job pretty simple:
http://www.odetocode.com/Articles/421.aspx

Hi Scott,

Thanks for the reply. I already saw that article, but unfortunately it
didn't help in my situation. The original page takes a querystring
parameter and uses that to load the product info from a database. When
the target page creates the PreviousPage object, it doesn't give it the
querystring parameter, so the PreviousPage object contains the info that
would be shown when an invalid product ID is passed. Obviously this
doesn't give me the info I want.

I actually managed to solve this part of the problem in a much simpler
way. It occurred to me to dump the contents of Request.Form into a
Literal to see what was in there. To my surprise, the controls I wanted
were shown with their original names. This made picking up the info
really easy!!

I'm now trying to do a similar thing where the original page shows a
list of products in a repeater, with each product having its own "buy"
button. That doesn't seem to be working as easily!! Any further
suggestions welcome.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top