473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Are dynamically loaded controls preserved over a postback?

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)
Nov 19 '05 #1
6 2025
you have to recreate the dynamic comtrol on postback. there is no code in
the placeholder for this.

-- bruce (sqlwork.com)

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:kb**************@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)

Nov 19 '05 #2
>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" <al*********@nospam.thanx> wrote in message
news:kb**************@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)
Nov 19 '05 #3
"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

Nov 19 '05 #4
>> 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)
Nov 19 '05 #5
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" <al*********@nospam.thanx> wrote in message
news:bq**************@nospamthankyou.spam...
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" <al*********@nospam.thanx> wrote in message
news:kb**************@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)

Nov 19 '05 #6
>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" <al*********@nospam.thanx> wrote in message
news:bq**************@nospamthankyou.spam...
>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" <al*********@nospam.thanx> wrote in message
news:kb**************@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)
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
1
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows ...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
2
by: A.Wussow | last post by:
Hi Everybody, i want to load dynamically content from some user controls (with forms, or some data-controls) using atlas. So i use an UpdatePanel for loading the user control into a placeholder....
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
7
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
2
by: Raymond Du | last post by:
Hi, I need to find a way to place multiple textboxes and other controls dynamically on a web form, I tried to put a placeholder on a form then create and add controls dynamically into the place...
1
by: =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?= | last post by:
Hi I have been banging my head for a few days now with this issue. I have a page that has several update panels everything is working fine except for 1 thing. I am creating a sort of wizard...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.