473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 1610
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**************@TK2MSFTNGP09.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.supernews.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**************@TK2MSFTNGP09.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.MyControl

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(MyNameSpace.MyControl))
{
//Cast it as the UserControl to expose any methods or properties and
do what you need to do.
((MyNameSpace.MyControl)ctrl).GetProperyOrMethod() ;
}

}

"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:u4**************@TK2MSFTNGP09.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.supernews.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**************@TK2MSFTNGP09.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
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...
2
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...
2
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...
2
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();...
4
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...
3
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...
3
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...
2
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...
3
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...
4
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.