Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Are dynamically loaded controls preserved over a postback?

Reply
Thread Tools

Are dynamically loaded controls preserved over a postback?

 
 
Alan Silver
Guest
Posts: n/a
 
      08-08-2005
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

--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
 
 
 
Bruce Barker
Guest
Posts: n/a
 
      08-08-2005
you have to recreate the dynamic comtrol on postback. there is no code in
the placeholder for this.

-- bruce (sqlwork.com)

"Alan Silver" <(E-Mail Removed)> wrote in message
news:kbQ$lsKW569CFwf$@nospamthankyou.spam...
> 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
>
> --
> Alan Silver
> (anything added below this line is nothing to do with me)



 
Reply With Quote
 
 
 
 
Alan Silver
Guest
Posts: n/a
 
      08-08-2005
>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" <(E-Mail Removed)> wrote in message
>news:kbQ$lsKW569CFwf$@nospamthankyou.spam...
>> 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
>>
>> --
>> Alan Silver
>> (anything added below this line is nothing to do with me)

>
>


--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      08-08-2005
"Alan Silver" wrote:

> >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?


Yes and no, depending on which stage of the page's life cycle the child
controls were created.

The following article on the MSDN is very useful in understanding the
ASP.NET View State:
http://msdn.microsoft.com/library/de.../viewstate.asp

Phillip Williams
http://www.societopia.net
http://www.webswapp.com

 
Reply With Quote
 
Alan Silver
Guest
Posts: n/a
 
      08-08-2005
>> If I recreate the user control, will the child controls have their
>> values preserved?

>
>Yes and no, depending on which stage of the page's life cycle the child
>controls were created.
>
>The following article on the MSDN is very useful in understanding the
>ASP.NET View State:
>http://msdn.microsoft.com/library/de.../en-us/dnaspp/
>html/viewstate.asp


Thanks, that's my bedtime reading sorted out tonight then!!

--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      08-09-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> >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" <(E-Mail Removed)> wrote in message
>>news:kbQ$lsKW569CFwf$@nospamthankyou.spam...
>>> 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
>>>
>>> --
>>> Alan Silver
>>> (anything added below this line is nothing to do with me)

>>
>>

>
> --
> Alan Silver
> (anything added below this line is nothing to do with me)



 
Reply With Quote
 
Alan Silver
Guest
Posts: n/a
 
      08-09-2005
>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" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> >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" <(E-Mail Removed)> wrote in message
>>>news:kbQ$lsKW569CFwf$@nospamthankyou.spam...
>>>> 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
>>>>
>>>> --
>>>> Alan Silver
>>>> (anything added below this line is nothing to do with me)
>>>
>>>

>>
>> --
>> Alan Silver
>> (anything added below this line is nothing to do with me)

>
>


--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
Dynamically Loaded controls loading other controls =?Utf-8?B?V291dGVy?= ASP .Net 3 02-27-2006 07:25 PM
Dynamic Loading of User Control with ViewState Preserved (Live Dem =?Utf-8?B?UHJvZGlwIEsgU2FoYQ==?= ASP .Net 0 10-28-2005 04:47 AM
Crystal Reports Cascading parameters don't get preserved between postbacks LP ASP .Net 19 02-25-2005 01:38 AM
State not preserved in inner controls of ASCX control Oleg Ogurok ASP .Net 1 06-23-2004 06:41 PM



Advertisments