Are dynamically loaded controls preserved over a postback?

A

Alan Silver

Hello,

I have a placeholder, which gets a user control added in when the page
first loads. This user control contains a dropdownlist, and I would like
to get hold of the value of this drop down list form the calling page on
postback. Can I do this? If I try and use FindControl on the
placeholder, it can't find the dropdownlist.

I tried...

ShowCategory ctlShowCategory = (ShowCategory)plcCategoryDetails.Controls[0];

(where ShowCategory is the user control) but this gave the error...

System.ArgumentOutOfRangeException: Specified argument was out of the
range of valid values. Parameter name: index

which sounds like the user control wasn't preserved in the placeholder
over the postback.

Any ideas how I do this? Hope this was clear!! TIA
 
B

Bruce Barker

you have to recreate the dynamic comtrol on postback. there is no code in
the placeholder for this.

-- bruce (sqlwork.com)
 
A

Alan Silver

you have to recreate the dynamic comtrol on postback. there is no code in
the placeholder for this.

If I recreate the user control, will the child controls have their
values preserved? The point of this is that I want to get the value of a
dropdownlist in the user control. If the value of that dropdownlist
isn't preserved (ie if recreating the user control resets the child
controls), then I'm wasting my time.

Thanks for the reply.
-- bruce (sqlwork.com)

Alan Silver said:
Hello,

I have a placeholder, which gets a user control added in when the page
first loads. This user control contains a dropdownlist, and I would like
to get hold of the value of this drop down list form the calling page on
postback. Can I do this? If I try and use FindControl on the placeholder,
it can't find the dropdownlist.

I tried...

ShowCategory ctlShowCategory =
(ShowCategory)plcCategoryDetails.Controls[0];

(where ShowCategory is the user control) but this gave the error...

System.ArgumentOutOfRangeException: Specified argument was out of the
range of valid values. Parameter name: index

which sounds like the user control wasn't preserved in the placeholder
over the postback.

Any ideas how I do this? Hope this was clear!! TIA
 
B

Bruce Barker

as long as you recreate all dynamic controls with the same name used on the
render, before page load, then they will receive their postback data. don't
overwrite their values on a postback.

its best to recreate dynamic controls in oninit()

-- bruce (sqlwork.com)



Alan Silver said:
you have to recreate the dynamic comtrol on postback. there is no code in
the placeholder for this.

If I recreate the user control, will the child controls have their values
preserved? The point of this is that I want to get the value of a
dropdownlist in the user control. If the value of that dropdownlist isn't
preserved (ie if recreating the user control resets the child controls),
then I'm wasting my time.

Thanks for the reply.
-- bruce (sqlwork.com)

Alan Silver said:
Hello,

I have a placeholder, which gets a user control added in when the page
first loads. This user control contains a dropdownlist, and I would like
to get hold of the value of this drop down list form the calling page on
postback. Can I do this? If I try and use FindControl on the
placeholder,
it can't find the dropdownlist.

I tried...

ShowCategory ctlShowCategory =
(ShowCategory)plcCategoryDetails.Controls[0];

(where ShowCategory is the user control) but this gave the error...

System.ArgumentOutOfRangeException: Specified argument was out of the
range of valid values. Parameter name: index

which sounds like the user control wasn't preserved in the placeholder
over the postback.

Any ideas how I do this? Hope this was clear!! TIA
 
A

Alan Silver

as long as you recreate all dynamic controls with the same name used on the
render, before page load, then they will receive their postback data. don't
overwrite their values on a postback.

its best to recreate dynamic controls in oninit()
Thanks

-- bruce (sqlwork.com)



Alan Silver said:
you have to recreate the dynamic comtrol on postback. there is no code in
the placeholder for this.

If I recreate the user control, will the child controls have their values
preserved? The point of this is that I want to get the value of a
dropdownlist in the user control. If the value of that dropdownlist isn't
preserved (ie if recreating the user control resets the child controls),
then I'm wasting my time.

Thanks for the reply.
-- bruce (sqlwork.com)

Hello,

I have a placeholder, which gets a user control added in when the page
first loads. This user control contains a dropdownlist, and I would like
to get hold of the value of this drop down list form the calling page on
postback. Can I do this? If I try and use FindControl on the
placeholder,
it can't find the dropdownlist.

I tried...

ShowCategory ctlShowCategory =
(ShowCategory)plcCategoryDetails.Controls[0];

(where ShowCategory is the user control) but this gave the error...

System.ArgumentOutOfRangeException: Specified argument was out of the
range of valid values. Parameter name: index

which sounds like the user control wasn't preserved in the placeholder
over the postback.

Any ideas how I do this? Hope this was clear!! TIA
 

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