473,569 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding dynamic controls with non-fixed names

I'm writing an app that uses a lot of time-date functions, so I'm trying to
create a calendar-type user control that adds a day, month, and year box to
a number of places on my page.

I can successfully dynamically create the controls, and add them to my page,
but I can only access them on postback if they've got a fixed name (so I can
declare them at the top of the page with the other web UI controls). If I
pass a value to create a name based on a string, I can't find any way of
accessing the postback values of them.

Has anyone got any ideas on how to get around this?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 09/10/2003
Nov 15 '05 #1
3 1623
Can you have a public value in the User Control to identify that control
from the other User Controls that you add, and then in the Postback, loop
through the Controls array of the container until you find the right type of
(typeof) control, cast it, get the identifier and do what you need to?

-Darrin

"Dunc" <du**@ntpcl.f9. co.uk> wrote in message
news:Or******** ******@TK2MSFTN GP09.phx.gbl...
I'm writing an app that uses a lot of time-date functions, so I'm trying to create a calendar-type user control that adds a day, month, and year box to a number of places on my page.

I can successfully dynamically create the controls, and add them to my page, but I can only access them on postback if they've got a fixed name (so I can declare them at the top of the page with the other web UI controls). If I
pass a value to create a name based on a string, I can't find any way of
accessing the postback values of them.

Has anyone got any ideas on how to get around this?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 09/10/2003

Nov 15 '05 #2
Not that I've been able to, as you still need to declare a variable, ergo
defeating the purpose of creating the controls at runtime with a name based
on a string parameter.

Duncan

"Darrin J Olson" <da************ @sio.midco.net> wrote in message
news:vp******** ****@corp.super news.com...
Can you have a public value in the User Control to identify that control
from the other User Controls that you add, and then in the Postback, loop
through the Controls array of the container until you find the right type of (typeof) control, cast it, get the identifier and do what you need to?

-Darrin

"Dunc" <du**@ntpcl.f9. co.uk> wrote in message
news:Or******** ******@TK2MSFTN GP09.phx.gbl...
I'm writing an app that uses a lot of time-date functions, so I'm trying

to
create a calendar-type user control that adds a day, month, and year box

to
a number of places on my page.

I can successfully dynamically create the controls, and add them to my

page,
but I can only access them on postback if they've got a fixed name (so I

can
declare them at the top of the page with the other web UI controls). If I pass a value to create a name based on a string, I can't find any way of
accessing the postback values of them.

Has anyone got any ideas on how to get around this?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 09/10/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.528 / Virus Database: 324 - Release Date: 16/10/2003
Nov 15 '05 #3
I may not be understanding your question correctly, but this is what I was
thinking:

Assume your UserControl is of type: MyNameSpace.MyC ontrol

In your postback on the aspx page that the controls were added to you can
loop through the controls on the web form:

//Loop through all controls on the page.
foreach(Control ctrl in this.Controls)
{
//Check to see if it is the UserControl.
if(ctrl.GetType () == typeof(MyNameSp ace.MyControl))
{
//Cast it as the UserControl to expose any methods or properties and
do what you need to do.
((MyNameSpace.M yControl)ctrl). GetProperyOrMet hod();
}

}

"Dunc" <du**@ntpcl.f9. co.uk> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl...
Not that I've been able to, as you still need to declare a variable, ergo
defeating the purpose of creating the controls at runtime with a name based on a string parameter.

Duncan

"Darrin J Olson" <da************ @sio.midco.net> wrote in message
news:vp******** ****@corp.super news.com...
Can you have a public value in the User Control to identify that control
from the other User Controls that you add, and then in the Postback, loop
through the Controls array of the container until you find the right type
of
(typeof) control, cast it, get the identifier and do what you need to?

-Darrin

"Dunc" <du**@ntpcl.f9. co.uk> wrote in message
news:Or******** ******@TK2MSFTN GP09.phx.gbl...
I'm writing an app that uses a lot of time-date functions, so I'm trying to
create a calendar-type user control that adds a day, month, and year
box to
a number of places on my page.

I can successfully dynamically create the controls, and add them to my page,
but I can only access them on postback if they've got a fixed name (so
I can
declare them at the top of the page with the other web UI controls).

If I pass a value to create a name based on a string, I can't find any way

of accessing the postback values of them.

Has anyone got any ideas on how to get around this?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 09/10/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.528 / Virus Database: 324 - Release Date: 16/10/2003

Nov 15 '05 #4

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

Similar topics

4
5465
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last...
2
4842
by: D Sheldon | last post by:
I am creating a server control that adds web controls (i.e. textboxes, etc) to a form. I use HtmlTable to build the table and insert the controls. Now I want to add validators to the textbox. Here is the code that I am using bool lastnamerequired=false public bool LastNameRequire get{return lastnamerequired; set{lastnamerequired = value;...
2
2100
by: Tim Marsden | last post by:
Hi, This is what I am doing, please comment if this is the correct way. I need to add controls to a form dynamically. Within the Page_Load event (is not Postback) I run a routine to create the controls, and populate the dropdowns etc, I use addhandler to define delegates to capture events raised by the controls. I store these controls...
2
2224
by: JezB | last post by:
I'm adding WebControl objects to a Page dynamically on Page_Load, but I'm having trouble attaching events to these. For example, adding an image button :- ImageButton nb = new ImageButton(); nb.ImageUrl = "text.gif"; nb.ToolTip = "Edit Text"; nb.Click += new ImageClickEventHandler(b1_Click); myPlaceholder.Controls.Add(nb);
4
2492
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...
3
1801
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a postback. The main question would be this: Why does this work for maintaining state after a postback for dynamic controls: myText = new...
3
1848
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New LiteralControl Dim lbtnCtrl As New LinkButton ltrCtrl.Text = "<br>" lbtnCtrl.Text = "WE: " & dtrCal(10).ToString lbtnCtrl.ToolTip = dtrCal(10).ToString & "...
2
2928
by: Ben Amada | last post by:
I'm a little confused about in what Event should I add dynamic controls and in what Event should I retrieve the value of a dynamic control on postback. I've found that adding dynamic controls in the Page Load event works, and I realize that I need to add the dynamic controls again on each postback. But if I'm trying to retrieve the value of...
3
2332
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example...
4
2191
by: Mike Lowery | last post by:
I have an ASP.Net page that simply generates a dynamic page using Response.Write() statements to generate the HTML. This works great except that one of the things I want to generate is a LinkButton. I know this can be done by creating a Panel and adding it using Panel.Controls.Add(LinkButton) but the problem is there are no controls on the...
0
7703
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...
0
7618
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...
0
7926
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. ...
0
7982
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...
0
6286
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...
1
5514
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...
0
3656
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...
1
2116
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
0
944
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...

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.