Dynamically generated control id is different at runtime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mazdotnet

    #1

    Dynamically generated control id is different at runtime

    Hi all,

    I have Repeater dynamically adding textboxes to a placeholder and
    connecting it to AjaxControlTool kit.PopupContro lExtender which works
    fine. I'm adding the textboxes using the following

    TextBox tbxQty = new TextBox();
    tbxQty.ID = "tbxQty" + id;
    phUserInput.Con trols.Add(tbxQt y);

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

    <input type="text" id="rptAvailabl eProducts_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 rptAvailablePro ducts_ctl01_tbx Qty0? Or in the OnCommand
    event is there any way to extract the value of tbxQty0 from
    rptAvailablePro ducts_ctl01_tbx Qty0?

    Thanks
    Maz
  • bruce barker

    #2
    Re: Dynamically generated control id is different at runtime

    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(t his, ctl =ctl.ID == "tbxQty" + id");


    public List<ControlCon trolWalker(
    Control ctl,
    Predicate<Contr olmatcher)
    {
    var list = new List<Control>() ;
    if (matcher(ctl)) list.Add(ctl);
    for (int i=0; i < ctl.Controls.Co unt; ++i)
    {
    var childList = ControlWalker(
    ctl.Controls[i],matcher);
    if (childList.Coun t 0)
    list.AddRange(c hildList);
    }
    return (list);
    }

    -- bruce (sqlwork.com)

    mazdotnet wrote:
    Hi all,
    >
    I have Repeater dynamically adding textboxes to a placeholder and
    connecting it to AjaxControlTool kit.PopupContro lExtender which works
    fine. I'm adding the textboxes using the following
    >
    TextBox tbxQty = new TextBox();
    tbxQty.ID = "tbxQty" + id;
    phUserInput.Con trols.Add(tbxQt y);
    >
    Now in the OnCommand I want to read the value of the textbox by using
    ((TextBox)FindC ontrol("tbxQty" + id)).Text which fails because my
    textbox automatically because
    >
    <input type="text" id="rptAvailabl eProducts_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 rptAvailablePro ducts_ctl01_tbx Qty0? Or in the OnCommand
    event is there any way to extract the value of tbxQty0 from
    rptAvailablePro ducts_ctl01_tbx Qty0?
    >
    Thanks
    Maz

    Comment

    Working...