User Controls-MasterPages and finding TextBox in DataList EditItemTemplate

Discussion in 'ASP .Net' started by Hillbilly, Sep 2, 2008.

  1. Hillbilly

    Hillbilly Guest

    Anybody have any sage advice on this frustrating "feature" of ASP.NET? I
    have a TextBox in the EditItemTemplate of a DataList I can't seem to find
    for some reason that is I believe related to the imfamous complexity and
    undocumented vagaries of user controls and MasterPages which are also a type
    of user control.
     
    Hillbilly, Sep 2, 2008
    #1
    1. Advertising

  2. Typically, you need to access template controls in one of the item events,
    like ItemCreated or ItemDataBound. Event parameters provide a reference to
    the item, something like e.Item. To detect EditItem, you need to check
    ItemType or check if (e.Item is ListItemType.EditItem). Once you have
    detected EditItem, you can use e.ItemFindControl("myTextBox") to get to the
    textbox.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Hillbilly" <> wrote in message
    news:O0zWW$...
    > Anybody have any sage advice on this frustrating "feature" of ASP.NET? I
    > have a TextBox in the EditItemTemplate of a DataList I can't seem to find
    > for some reason that is I believe related to the imfamous complexity and
    > undocumented vagaries of user controls and MasterPages which are also a
    > type of user control.
     
    Eliyahu Goldin, Sep 2, 2008
    #2
    1. Advertising

  3. Hillbilly

    bruce barker Guest

    RE: User Controls-MasterPages and finding TextBox in DataList EditItem

    there is nothing really complex about it. html (and asp.net) is a
    parent/child (tree) data structure. recursion was invented to handle this
    common data structure.

    var list = ControlWalker(this, ctl => ctl.ID == "textboxid");
    ....

    public List<Control> ControlWalker(
    Control ctl,
    Predicate<Control> matcher)
    {
    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,matcher);
    if (childList.Count > 0)
    list.AddRange(childList);
    }
    return (list);
    }


    -- bruce (sqlwork.com)


    "Hillbilly" wrote:

    > Anybody have any sage advice on this frustrating "feature" of ASP.NET? I
    > have a TextBox in the EditItemTemplate of a DataList I can't seem to find
    > for some reason that is I believe related to the imfamous complexity and
    > undocumented vagaries of user controls and MasterPages which are also a type
    > of user control.
    >
    >
     
    bruce barker, Sep 2, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia
    Replies:
    1
    Views:
    492
    John Saunders
    Jan 6, 2005
  2. Replies:
    1
    Views:
    1,787
    Grant Merwitz
    Sep 27, 2005
  3. Nick Wouters
    Replies:
    5
    Views:
    4,641
    Flinky Wisty Pomm
    May 8, 2006
  4. JohnE

    masterpages with masterpages

    JohnE, Dec 7, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    491
    Hillbilly
    Dec 8, 2009
  5. Replies:
    1
    Views:
    255
    Grant Merwitz
    Sep 27, 2005
Loading...

Share This Page