473,626 Members | 3,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList & Dynamic UserControls

Okay, I'm pretty sure that I'm doing everything right here, but
something is very wrong in the result.

I've a page that has a drop down list (with auto-post-back = true) and
a place holder.

During page load, I'm loading a control dynamically (using
LoadControl()) and adding it to the place holder.

In the control OnInit(), I load some values into it.

The issue is when the page is doing a post back (when the page's drop
down list changes).

Then I load another control (totally different), which has another drop
down list (with a different Id then the one on the first control.)
In the 2nd control OnInit(), I load different values into the control's
drop down list.
I then add it to the page.

On the page I get the _first control's drop down list values_!

I debugged it, and it seems that the old drop down list values are
being added to the new drop down list when I add it to the place holder
on the page.

I've no idea why, since they have a different id and are loaded in a
totally different user control.

If I move the adding of values to the load event, the old values are
still there, and they appear first, and then the new values.

If I disable the view state of either control, everything works as it
should. But I need the view state for those controls.

I've a demo of the bug at:
http://www.ayende.com/DropDownListBug.zip

Nov 20 '05 #1
1 1684
In case someone else has the same problem, the issue is that ASP.Net
loads the controls by index, and not by ID.
You can see the docs here:
http://msdn2.microsoft.com/en-us/lib...attribute.aspx

It can be solved by simply annotating the control with a
ViewStateModeBy Id attribute.

Nov 21 '05 #2

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

Similar topics

7
2857
by: Piotr Strycharz | last post by:
Hi all. I have problem with ASP:DropDownList. I do not know how to get its value. The DropDownList is populated in Page_Load method (from SQL Server). When this list is embeded in ASPX page everything runs fine: I can use Request.Form to know its value. However, when I use it in control (ASCX) the framework adds something like "ctl5_:" to the name of the control. So Request.Form method does not work. What is NOT working too, is the...
2
344
by: Jennyfer J Barco | last post by:
Hello is there a way to create a dropdownlist inside a <input type='dropdownlist'> or there is an equivalent to create other than <asp:DropDownList id="drop1" runat="server"> . I need this because it's a dynamic page and I need to create the dropdown control in any position needed depending on what the user selected, so I'm creating this dropdownlist at run time. Thanks in advance Jennyfer
2
3744
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the <asp:EditCommandColumn> I want either a textbox or dropdown to appear when I check what is being edited. I thought I could create the dropdown on the fly and add it to the datagrid as below but It's not appearing. I imagined I could populate the dropdown
2
1967
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page submit. I've read several post here and articles on the web on this topic. What little I have learned from them is that you have to pre-compile the usercontrol in order to access it in the aspx code behind. I did this, compiling the usercontrol...
4
3834
by: Jeff | last post by:
Help.... I have formatted a lsit of strings to add to a dropdownlist to shows three colums: id, description and price. i.e. 123 description here $12.95 12456 another description $123.01 But when the text is rendered the white space is removed so it looks like this:
1
2347
by: Gummy | last post by:
Hello, I am loading several user controls dynamically in OnInit() like this: ucListBoxSelections ucLocation = (ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");
2
1622
by: OJ | last post by:
Hi, ASP.NET C# 2.0 I have a usercontrol which contains a Gridview. I create my own DataTable to bind to the GridView, which then fires the RowDataBound event of the the Gridview. Here I add a dropdownlist to the relevent row.Cell. I then expose the GridView as a public property of the usercontrol. This all works lovely. However, when I try to find the dropdownlist by accessing the GridView property of the usercontrol on the ASP next...
1
4650
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3491
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
6
4269
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist boxes are generating a postback.here is a code . protected void Page_Load(object sender, EventArgs e) { int selected_question = (int)Session; if (!Page.IsPostBack) { display_blueprint(); string...
0
8262
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
8701
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
8364
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
7192
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
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
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
4196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2623
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
2
1507
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.