How get value from a dynamically created control in a user control


I am working with a version of IBuySpy. On one page is a form that contains a user control that lists the items the user purchased, the subtotal, shipping, etc. I wanted to add a DropDownList from which the user could select the shipper. The dropdown list works fine as long as it has .AutoPostBack = false. However, I cannot figure out how to get the value that the user selected when they finally press the submit button on the form.
All attempts to locate the control and it's value have failed. I tried drillingdown from the form to the child controls, and sub child controls. No where in this try can I find my dynamically created DropDownList. I am starting to suspect that unless you have .AutoPostBack = true and an event handler that the value of a dynamically created control is lost when the form is submitted. Can anyone veryify that this is the case.
If it is the case, how can you get this value? The reason I had to set .AutoPostBack =false is because also on the user control was grid and it was in the footer of the grid is where my control is created. I suppose I could gut the control and put my controls outside the grid, but I thoi\ught I would see if there was an easier way.
11/20/2004 3:48:42 AM 93655 articles. 5 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 32

You can use Control.FindControl to find named sub control in your control.

Check this sample Accessing Control's Value from DataGrid in ASP.NET
OR You can expose public property of usercontrol pass value to parent.
Check this Extracting Child UserControl's value

<%@ Page Language="C#" %>
<%@ Register TagPrefix="Test" TagName="MyControl" Src="ExtractingSUBControlsvalue.ascx" %>
<script runat="server">
void btnClick(Object sender,EventArgs e)
result.Text = "Name: " + TestControl1.SelectedUserName + "<br />";
result.Text += "ID: " + TestControl1.SelectedUserID ;
<head runat="server">
<title>Extracting Child UserControl's value</title>
<form id="form1" runat="server">
<p>Following example shows how you can access values from
Child UserControl using public property in user control.
<p style="border:solid 1px;padding: 5px;">
<Test:MyControl id="TestControl1" runat="server"/>
<asp:Button Runat="server" onclick="btnClick" Text="Get UserControl Data"/>
<asp:Label ID="result" Runat=Server></asp:Label>
<%@ Control Language="C#" %>
<%@ import Namespace="System.Collections" %>
<script runat="server">
public String SelectedUserName {get { return UserList.SelectedItem.Text; }}
public String SelectedUserID { get { return UserList.SelectedItem.Value; }}

This is UserContorl.
<br />
<asp:DropDownList runat="server" ID="UserList">
<asp:ListItem Value="1">Tom Sawyer</asp:ListItem>
<asp:ListItem Value="2">Huckleberry Finn</asp:ListItem>
<asp:ListItem Value="3">Robinson Crusoe</asp:ListItem>
<asp:ListItem Value="4">William Tell</asp:ListItem>

Jigar Desai
Do not forget to "Mark as Answer" on the post that helped you.
11/20/2004 5:28:54 PM

Similar Artilces:

User Control controls not created when dynamically creating user control
  Have created a user control for displaying and editing a dynamically number of values. The user control contains two labels and an edit box. When dynamically loading the user control I get an error when the control itself tries to change setting on the fields within the user control.   Why doesnt this work? It works okay if I dont load it dynamically but create a user-control-instance in the aspx-page but thats no solution.   Thankyou!     Here is my code:   ucDataValue.ascx   <%@ Control Language="C#" AutoEventWireup="true&...

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

Reading form values in dynamically created child controls in a user control
I have a common problem for which I've searched the web for answers for hours to no avail. I have some radiobuttonlists ,dropdownlists,checkboxlists and text controls in a user control. The lists are created statically, however the items in the lists are populated at run time. The lists are displayed in default.aspx (the containing page) and populated on the Page_Load event of the user control .ascx file based on an external data source containing arrays of data. I want to be able to read the values selected by the user from deafult.aspx, the parent page. details: The .ascx...

Get user input from dynamic created control, why i cant get the value???
Hi!, i was tried to dynamically generate some textboxes according the selected number in a dropdownlist, but when i need to get the user input from those textboxes.. i cant get at all!!, Can any1 guide me on tis? Below is my code.Basically, i have 1 dropdownlist (ddltbCount), 1 placeHolder(Pholder1), 1 button(btGetValue), i dont know y i cant post the html here... Private count As Integer = 1 Sub IterateThroughChildren(ByVal parent As Control) For Each c As Control In parent.Controls If c.GetType.ToString.Equals("System.Web.UI.WebControls.TextBox") AndAlso c.ID Is Nothing Then ' CType(c, T...

Problems with UpdatePanel, Web User Control and Dynamic Controls Creating
Hi,In a Page, i have a button that's outside an UpdatePanel, but that triggers him. That UpdatePanel get refreshed with a Web User Control inside it. The Web User Control, has come logic to dynamically create some Controls (TextBox and other simple controls), and he does that very well, and the UpdatePanel get refreshed ok and the controls get rendered to the browser. The problem is when i click in a Button inside the Web User Control (not dynamically created), and i can't get the controls values in the server-side. Before the server side event of the Button Click, i re-create all the contro...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Dynamically Loading User Control and Maintaining its viewstate. And Getting Values from the control.
 I have a drop down which is populated on the page looad.  When i select an item from drop downlist i get to see two listboxes with add/removing the objects from one left to right listbox and below that i have a user control which should be populated dynamically based on the selectedvalue from drop down list.  So there are three sections that are seen once a selected value is consiedered from drop down list.  Now I am getting the user control using the below code givencase "42": viewRequired = "vw_AncCostSavingsByCarrier_adhoc";    ...

Custom User Controls and dynamically created web controls events not firing
I have a peculiar problem and since I am just starting to use .net I am confident I am doing something wrong, but I can't see it and I've wasted a lot of time so far trying to figure it out. Hopefully one of you can figure it out. I have a custom User Control and I am dynamically creating a RadioButtonList. If I remove the custom user control from the page the RadioButtonList works as expected and correctly. However, once I add the custom control, it does not fire the SelectedIndexChanged event. Below is some code. If all I do is remove: "<UC:TOPMENU id="TopMenu1"...

User Control Issue
Dupelicate post dancioffi: Dupelicate post Please refer to this: yang - MSFTMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Bubbling Events on Dynamically created controls that are on dynamically created user-controls on a module!! HELP MAH PUHLEASE!
I may be cross posting this question, but I am really going to go crazy.. Please help if you can!I think I am going to go mad. If anyone can help me with this small issue, I will build an idol in your image made of clay, and have nubile maidens dance in front of it in worship!!!!I have a module. Let's call it Module-1Module-1 Connects to a database and gets a list of items.Module-1 Then creates on the fly a number of buttons that represent that list of items.Each button when clicked dynamically creates a web-user control. Let's pull out 1 button, and 1 usercontrol and call them Button-1 and ...

Dynamically creating a user control AND then setting and accessing its controls' values... RELP!
Hello all!  I am new to user controls and this problem I'm sure is something tiny and solved simply.  However, as we are all aware... in the computer world, a single line or even character can make all the difference. Here goes... - I've created a user control with 2 textboxes on it.  From my aspx page, I wish to dynamically load 1 or more of these based on the data being retrieved.  The data are "Person" objects. - As these controls are created and added to the panel on the aspx form, I'd like to set the te...

How to get the value of dynamically created text box which is created dynamically on click of button control.
<p>Dear AllI am new in am doing one project there I have one doubt.what I want is I have taken two  button controls in my page, in click of first button1 I have  dynamically created one textbox and I added this textbox to my page and also set the id for this textbox,.after that in click of second button2 I want that the value of the textbox will be print in my page by getting the value of the textbbox. some codes are given below. <form id="form1" runat="server">    <div>      ...

Web resources about - How get value from a dynamically created control in a user control -

Placebase team at Apple file “Schematic Maps” patent dynamically detailing important data
In a report from Computerworld way back in 2009, we learned that Apple had quietly acquired Maps API company Placebase. Then, founder of Placebase ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

In a dynamically typed language, is it a bad idea to return different data types?
In some cases, returning different types from a single function works.

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ... launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...

A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97% Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 1/16/2016 4:43:15 PM