473,320 Members | 1,823 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,320 software developers and data experts.

Dynamically generated control id is different at runtime

Hi all,

I have Repeater dynamically adding textboxes to a placeholder and
connecting it to AjaxControlToolkit.PopupControlExtender which works
fine. I'm adding the textboxes using the following

TextBox tbxQty = new TextBox();
tbxQty.ID = "tbxQty" + id;
phUserInput.Controls.Add(tbxQty);

Now in the OnCommand I want to read the value of the textbox by using
((TextBox)FindControl("tbxQty" + id)).Text which fails because my
textbox automatically because

<input type="text" id="rptAvailableProducts_ctl01_tbxQty0" />
instead of
<input type="text" id="tbxQty0" />

How can I force it to use tbxQty0 for the generated id at runtime
instead of rptAvailableProducts_ctl01_tbxQty0? Or in the OnCommand
event is there any way to extract the value of tbxQty0 from
rptAvailableProducts_ctl01_tbxQty0?

Thanks
Maz
Sep 27 '08 #1
1 1734
FindControl() only searches the current naming container. to use
findcontrol, you need to call it on the datarepeater template that hosts
the control. i assume you made a unique id, so you can just do a
recursive search for a control with the id.
var list = ControlWalker(this, ctl =ctl.ID == "tbxQty" + id");
public List<ControlControlWalker(
Control ctl,
Predicate<Controlmatcher)
{
var list = new List<Control>();
if (matcher(ctl)) list.Add(ctl);
for (int i=0; i < ctl.Controls.Count; ++i)
{
var childList = ControlWalker(
ctl.Controls[i],matcher);
if (childList.Count 0)
list.AddRange(childList);
}
return (list);
}

-- bruce (sqlwork.com)

mazdotnet wrote:
Hi all,

I have Repeater dynamically adding textboxes to a placeholder and
connecting it to AjaxControlToolkit.PopupControlExtender which works
fine. I'm adding the textboxes using the following

TextBox tbxQty = new TextBox();
tbxQty.ID = "tbxQty" + id;
phUserInput.Controls.Add(tbxQty);

Now in the OnCommand I want to read the value of the textbox by using
((TextBox)FindControl("tbxQty" + id)).Text which fails because my
textbox automatically because

<input type="text" id="rptAvailableProducts_ctl01_tbxQty0" />
instead of
<input type="text" id="tbxQty0" />

How can I force it to use tbxQty0 for the generated id at runtime
instead of rptAvailableProducts_ctl01_tbxQty0? Or in the OnCommand
event is there any way to extract the value of tbxQty0 from
rptAvailableProducts_ctl01_tbxQty0?

Thanks
Maz
Sep 27 '08 #2

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

Similar topics

20
by: David | last post by:
I have a one-line script to add an onunload event handler to the body of the document. The script is as follows: document.getElementsByTagName("BODY").onunload=function s() {alert("s")} Now...
0
by: Verane | last post by:
Hi all, I am working with C# and Visual studio 2003. What I want to do is the following : I have 3 assemblies, let call them A.exe, B.dll and C.dll. I want to dynamically load B and C when A...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
6
by: Nathan Sokalski | last post by:
I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls such as Label controls, because they can be placed...
15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
7
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al =...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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

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.