473,698 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET 1.1 dynamically added controls


Hi,

I am having troubles dealing with dynamically created WebControls. I have
this HTML code:

<form id="Form1" runat="server" method="post">
<table width="960" align="center">
<tr>
<td align="center">
......
<td colspan="5">
<div id="plhFilters " runat="server"> </div>
.........

I added the following code in Page_Load of the code-behind:

ddlStage.DataSo urce = clsBbDataAccess .getStages()
ddlStage.DataVa lueField = "value"
ddlStage.DataTe xtField = "name"
ddlStage.DataBi nd()
ddlStage.Items. Insert(0, "")
plhFilters.Cont rols.Add(ddlSta ge)
ddlStage.ID = row("WebControl _name")

I then have a button on the page that does a postback, where I should read
the value of the dynamically created DropDownList. But my control is always
set to Nothing when I am in the code-behind after the postback occurred.

I also tried to set the "EnableViewStat e" property to "true", without luck.

What am I doing wrong here?

Thanks.
Mike
Jun 22 '06 #1
1 1794
Dynamically added controls need to be re-added on postback. They aren't
automatically re-created/re-added for you. This typically has to happen on
or before Page_Load. If viewstate is enabled, you don't need to repopulate
it (it will repopulate from viewstate), but first you must re-recreate it.

One (free) solution is Denis Bauer's DynamicPlaceHol derControl which
remembers any dynamically added controls and re-creates it for you:
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Karl
--
http://www.openmymind.net/

"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:04******** *************** ***********@mic rosoft.com...

Hi,

I am having troubles dealing with dynamically created WebControls. I have
this HTML code:

<form id="Form1" runat="server" method="post">
<table width="960" align="center">
<tr>
<td align="center">
......
<td colspan="5">
<div id="plhFilters " runat="server"> </div>
.........

I added the following code in Page_Load of the code-behind:

ddlStage.DataSo urce = clsBbDataAccess .getStages()
ddlStage.DataVa lueField = "value"
ddlStage.DataTe xtField = "name"
ddlStage.DataBi nd()
ddlStage.Items. Insert(0, "")
plhFilters.Cont rols.Add(ddlSta ge)
ddlStage.ID = row("WebControl _name")

I then have a button on the page that does a postback, where I should read
the value of the dynamically created DropDownList. But my control is
always
set to Nothing when I am in the code-behind after the postback occurred.

I also tried to set the "EnableViewStat e" property to "true", without
luck.

What am I doing wrong here?

Thanks.
Mike

Jun 22 '06 #2

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

Similar topics

4
2496
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
4
3111
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...
5
3729
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of controls to the webpage using the innerHTML method. It appears to work perfectly fine in the browser. The...
3
2538
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those controls are not present nor their valves in Request.Form.AllKeys.
5
1958
by: Chris | last post by:
I have a page with mixture of static and dynamically added controls is there any way of controlling the order which they are added to the page. My submit button (statically added) appears before some textboxes (dynamically added). I know I could move it around with CSS but I want to move towards an accessible site that will display forms in the right order without CSS. Regards, Chris.
7
2141
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
5
4450
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not survive postback. This seems to be true. However, this seems to make dynamically adding controls rather pointless to me, since if you cannot retrieve the values of the controls when you perform a postback, why add the controls in the firstplace?...
1
4899
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have set text boxes and labels inside the table rows. I then added a button. All of these are done through code. The problem that i am having is i can get the value from a text box with resides inside the first panel (out side of panel that is...
7
6656
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
0
8674
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
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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
4366
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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
2001
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.