473,781 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)p lcCategoryDetai ls.Controls[0];

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

System.Argument OutOfRangeExcep tion: 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 2042
you have to recreate the dynamic comtrol on postback. there is no code in
the placeholder for this.

-- bruce (sqlwork.com)

"Alan Silver" <al*********@no spam.thanx> wrote in message
news:kb******** ******@nospamth ankyou.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)p lcCategoryDetai ls.Controls[0];

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

System.Argument OutOfRangeExcep tion: 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*********@no spam.thanx> wrote in message
news:kb******* *******@nospamt hankyou.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)p lcCategoryDetai ls.Controls[0];

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

System.Argument OutOfRangeExcep tion: 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*********@no spam.thanx> wrote in message
news:bq******** ******@nospamth ankyou.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*********@no spam.thanx> wrote in message
news:kb****** ********@nospam thankyou.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)p lcCategoryDetai ls.Controls[0];

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

System.Argument OutOfRangeExcep tion: 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*********@no spam.thanx> wrote in message
news:bq******* *******@nospamt hankyou.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*********@no spam.thanx> wrote in message
news:kb***** *********@nospa mthankyou.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)p lcCategoryDetai ls.Controls[0];

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

System.Argument OutOfRangeExcep tion: 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
4316
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
1
2589
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 LinkButton myLB = new LinkButton(); ......... .........
4
3119
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 UserControls into the PlaceHolder's child control collection depending upon which of the three radio buttons is selected. Each of the three UserControls have postback events themselves triggered by button clicks. The problem I'm having is keeping track of...
6
3381
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 the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display the user control - select user control button, event fires - select web form button to display...
2
1802
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. Using buttons for loading new content works fine. But i still want to use a function which is callable per javascript. I think this way is more flexable than using the Buttons, becaus every button needs it's own Sub-Routine. But i want to have...
1
7596
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 usercontrol is a button and a label. Everytime the button is clicked a counter which is stored in the viewstate is increased and displayed in the label.
7
2152
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 CType(Me.FindControl("admin" & CStr(section("buttontext")).Replace(" ", "")), adminsection2).RefreshSection() Next End Sub
2
2136
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 holder. It is not working, all controls added disappear after the postback. I tried to find a working sample on Internet with no lucks, some samples are able to keep the controls after the postback, but all values entered before the postback...
1
1944
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 that will build a form that I plan to save to a database On stage 2 I load a usercontrol an unspecified number of times depending on
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.