Composite Control Losing events.

Discussion in 'ASP .Net Web Controls' started by Ashish, May 22, 2006.

  1. Ashish

    Ashish Guest

    HI all,
    I have been battling with this problem with some time now, now iam out
    of ideas what to do
    basically iam planning a tab control in which page developers can define
    tab abd tabelements on the page, and i can render a table with one row
    being link buttons and second row with tabelements..

    tha markup of the control looks like

    <uc:TabStrip ID="tbMatrixProduct" runat="server">
    <uc:TabElement ID="teGeneral" runat="server" Description="General">
    <uc:GeneralProduct ID="GeneralProduct1" runat="server" />

    </uc:TabElement>
    <uc:TabElement ID="teDescription" runat="server"
    Description="Description">
    <uc:productDescription ID="ProductDescription1" runat="server" />
    </uc:TabElement>
    </uc:TabStrip>

    i have two controls with tabcontrol having ParseChildren Attribute, and
    having a ControlBuilder defined for TabElement.

    The RenderChildControl method looks like


    protected override void CreateChildControls()
    {

    Controls.Clear();
    Table cTable = new Table();
    cTable.ID = "tbl" + this.ID;

    cTable.Rows.Add(new TableRow());
    //create link button row and add a link button for each tab
    double width = Math.Floor((double)100 / (Elements.Count+1));

    foreach(TabElement element in mElements)
    {
    //create link buttons here
    }

    TableCell panelcell = new TableCell();
    panelcell.ColumnSpan = mElements.Count +1 ;
    panelcell.Width = new Unit( "100%");

    // create tabelements controls here
    foreach (TabElement element in mElements)
    {
    Panel holder = new Panel();
    holder.ID = "pnl" + element.ID;
    holder.Controls.Add(element);
    holder.Visible = (VisibleTabId == element.ID);
    panelcell.Controls.Add(holder);
    }


    so far so good, everything comes up just fine, but one of the
    usercontrols in tabelements is having nested datalist..., thats where
    thr trouble begins...

    the child datalist is having link buttons, and their event handlers
    never get called ...

    I can put the user control on the page and it works fine, but when i put
    it on my TabControl, it stops firing events...

    I have tried wiring up events on the markup, in the code behind
    everywhere, but the events dont get called.


    I can confirm that the usercontrol is not loading the entire datalists
    on the post back, but i dont know why, and how can i make it..., i can
    post the whole code if someone is interested in looking at the problem...

    thanks
    Ashish, May 22, 2006
    #1
    1. Advertising

  2. Ashish

    Guest

    Ashish. The most common reason for this problem is usually because you're not
    adding the child control's to the Control's early enough.
    Your child controls and any controls for that matter need to be a part of
    the whole Page hiearchy no later then Onload (generally speaking). You can go
    later, but the later you go the more prone to problems you are.

    So you should go through hopefully with a debugger and make sure all of your
    controls are part of the hierarchy by the time OnLoad triggers. You should
    also make sure that all of these controls have a specified ID and that this
    ID is the same upon postback. Also double verify that the events are being
    attached and the appropriate __doPostBack is being generated.

    Another thing that your Control should do is implement the methodless
    Interface INamingContainer. This ensures that your control has a
    NamingContainer example $ctl00$Mycontrol$lnkChild and can also solve lots of
    similar problems.

    Hope this helps.
    "Ashish" wrote:

    >
    > HI all,
    > I have been battling with this problem with some time now, now iam out
    > of ideas what to do
    > basically iam planning a tab control in which page developers can define
    > tab abd tabelements on the page, and i can render a table with one row
    > being link buttons and second row with tabelements..
    >
    > tha markup of the control looks like
    >
    > <uc:TabStrip ID="tbMatrixProduct" runat="server">
    > <uc:TabElement ID="teGeneral" runat="server" Description="General">
    > <uc:GeneralProduct ID="GeneralProduct1" runat="server" />
    >
    > </uc:TabElement>
    > <uc:TabElement ID="teDescription" runat="server"
    > Description="Description">
    > <uc:productDescription ID="ProductDescription1" runat="server" />
    > </uc:TabElement>
    > </uc:TabStrip>
    >
    > i have two controls with tabcontrol having ParseChildren Attribute, and
    > having a ControlBuilder defined for TabElement.
    >
    > The RenderChildControl method looks like
    >
    >
    > protected override void CreateChildControls()
    > {
    >
    > Controls.Clear();
    > Table cTable = new Table();
    > cTable.ID = "tbl" + this.ID;
    >
    > cTable.Rows.Add(new TableRow());
    > //create link button row and add a link button for each tab
    > double width = Math.Floor((double)100 / (Elements.Count+1));
    >
    > foreach(TabElement element in mElements)
    > {
    > //create link buttons here
    > }
    >
    > TableCell panelcell = new TableCell();
    > panelcell.ColumnSpan = mElements.Count +1 ;
    > panelcell.Width = new Unit( "100%");
    >
    > // create tabelements controls here
    > foreach (TabElement element in mElements)
    > {
    > Panel holder = new Panel();
    > holder.ID = "pnl" + element.ID;
    > holder.Controls.Add(element);
    > holder.Visible = (VisibleTabId == element.ID);
    > panelcell.Controls.Add(holder);
    > }
    >
    >
    > so far so good, everything comes up just fine, but one of the
    > usercontrols in tabelements is having nested datalist..., thats where
    > thr trouble begins...
    >
    > the child datalist is having link buttons, and their event handlers
    > never get called ...
    >
    > I can put the user control on the page and it works fine, but when i put
    > it on my TabControl, it stops firing events...
    >
    > I have tried wiring up events on the markup, in the code behind
    > everywhere, but the events dont get called.
    >
    >
    > I can confirm that the usercontrol is not loading the entire datalists
    > on the post back, but i dont know why, and how can i make it..., i can
    > post the whole code if someone is interested in looking at the problem...
    >
    > thanks
    >
    >
    , May 23, 2006
    #2
    1. Advertising

  3. Ashish

    Ashish Guest

    hi there,
    thanks for your interest in this problem,

    after a couple of days of search and frustation, i found out following
    things, please let me know if you see anything wrong in them

    1. CreateChildControls at OnLoad ( some postbacks started to fire after
    this)

    2. CreateChildControls again at PreRender -- this is because new
    databindings might create new child controls ( again more improvements
    after i did this)

    3. Iam using CompositeControl which i think should take care of the
    NamingContainer issue.

    4. The control in which Gridview is embedded in a datalist works fine
    now, with all events firing as expected, but the control in which
    datalist is embedded in a datalist is the child datalist's events dont
    fire !

    Would appreciate if you could give any other pointers

    thanks



    wrote:
    > Ashish. The most common reason for this problem is usually because you're not
    > adding the child control's to the Control's early enough.
    > Your child controls and any controls for that matter need to be a part of
    > the whole Page hiearchy no later then Onload (generally speaking). You can go
    > later, but the later you go the more prone to problems you are.
    >
    > So you should go through hopefully with a debugger and make sure all of your
    > controls are part of the hierarchy by the time OnLoad triggers. You should
    > also make sure that all of these controls have a specified ID and that this
    > ID is the same upon postback. Also double verify that the events are being
    > attached and the appropriate __doPostBack is being generated.
    >
    > Another thing that your Control should do is implement the methodless
    > Interface INamingContainer. This ensures that your control has a
    > NamingContainer example $ctl00$Mycontrol$lnkChild and can also solve lots of
    > similar problems.
    >
    > Hope this helps.
    > "Ashish" wrote:
    >
    >
    >>HI all,
    >>I have been battling with this problem with some time now, now iam out
    >>of ideas what to do
    >>basically iam planning a tab control in which page developers can define
    >>tab abd tabelements on the page, and i can render a table with one row
    >>being link buttons and second row with tabelements..
    >>
    >>tha markup of the control looks like
    >>
    >> <uc:TabStrip ID="tbMatrixProduct" runat="server">
    >> <uc:TabElement ID="teGeneral" runat="server" Description="General">
    >> <uc:GeneralProduct ID="GeneralProduct1" runat="server" />
    >>
    >> </uc:TabElement>
    >> <uc:TabElement ID="teDescription" runat="server"
    >>Description="Description">
    >> <uc:productDescription ID="ProductDescription1" runat="server" />
    >> </uc:TabElement>
    >> </uc:TabStrip>
    >>
    >>i have two controls with tabcontrol having ParseChildren Attribute, and
    >>having a ControlBuilder defined for TabElement.
    >>
    >>The RenderChildControl method looks like
    >>
    >>
    >>protected override void CreateChildControls()
    >> {
    >>
    >> Controls.Clear();
    >> Table cTable = new Table();
    >> cTable.ID = "tbl" + this.ID;
    >>
    >> cTable.Rows.Add(new TableRow());
    >> //create link button row and add a link button for each tab
    >> double width = Math.Floor((double)100 / (Elements.Count+1));
    >>
    >> foreach(TabElement element in mElements)
    >> {
    >> //create link buttons here
    >> }
    >>
    >> TableCell panelcell = new TableCell();
    >> panelcell.ColumnSpan = mElements.Count +1 ;
    >> panelcell.Width = new Unit( "100%");
    >>
    >> // create tabelements controls here
    >> foreach (TabElement element in mElements)
    >> {
    >> Panel holder = new Panel();
    >> holder.ID = "pnl" + element.ID;
    >> holder.Controls.Add(element);
    >> holder.Visible = (VisibleTabId == element.ID);
    >> panelcell.Controls.Add(holder);
    >> }
    >>
    >>
    >>so far so good, everything comes up just fine, but one of the
    >>usercontrols in tabelements is having nested datalist..., thats where
    >>thr trouble begins...
    >>
    >>the child datalist is having link buttons, and their event handlers
    >>never get called ...
    >>
    >>I can put the user control on the page and it works fine, but when i put
    >>it on my TabControl, it stops firing events...
    >>
    >>I have tried wiring up events on the markup, in the code behind
    >>everywhere, but the events dont get called.
    >>
    >>
    >>I can confirm that the usercontrol is not loading the entire datalists
    >>on the post back, but i dont know why, and how can i make it..., i can
    >>post the whole code if someone is interested in looking at the problem...
    >>
    >>thanks
    >>
    >>
    Ashish, May 23, 2006
    #3
  4. Ashish

    Guest

    I suggest putting a INamingContainer on it "just" in case. It's a painless
    method just tack on a , INamingContainer and recompile and etc. It doesn't
    have any other code that you have to implement.

    The second thing to do is to put a break point on the Control's Load and
    when you click a link take a look at the Request.Form variables there are 2
    or 3 keys that you want to look at . Pay careful attention to the key that
    specifies what control invoked the event. Then go find that control and find
    out what it's UniqueID / ClientID is. Also double check, is that control's
    event getting bound before or after?



    "Ashish" wrote:

    > hi there,
    > thanks for your interest in this problem,
    >
    > after a couple of days of search and frustation, i found out following
    > things, please let me know if you see anything wrong in them
    >
    > 1. CreateChildControls at OnLoad ( some postbacks started to fire after
    > this)
    >
    > 2. CreateChildControls again at PreRender -- this is because new
    > databindings might create new child controls ( again more improvements
    > after i did this)
    >
    > 3. Iam using CompositeControl which i think should take care of the
    > NamingContainer issue.
    >
    > 4. The control in which Gridview is embedded in a datalist works fine
    > now, with all events firing as expected, but the control in which
    > datalist is embedded in a datalist is the child datalist's events dont
    > fire !
    >
    > Would appreciate if you could give any other pointers
    >
    > thanks
    >
    >
    >
    > wrote:
    > > Ashish. The most common reason for this problem is usually because you're not
    > > adding the child control's to the Control's early enough.
    > > Your child controls and any controls for that matter need to be a part of
    > > the whole Page hiearchy no later then Onload (generally speaking). You can go
    > > later, but the later you go the more prone to problems you are.
    > >
    > > So you should go through hopefully with a debugger and make sure all of your
    > > controls are part of the hierarchy by the time OnLoad triggers. You should
    > > also make sure that all of these controls have a specified ID and that this
    > > ID is the same upon postback. Also double verify that the events are being
    > > attached and the appropriate __doPostBack is being generated.
    > >
    > > Another thing that your Control should do is implement the methodless
    > > Interface INamingContainer. This ensures that your control has a
    > > NamingContainer example $ctl00$Mycontrol$lnkChild and can also solve lots of
    > > similar problems.
    > >
    > > Hope this helps.
    > > "Ashish" wrote:
    > >
    > >
    > >>HI all,
    > >>I have been battling with this problem with some time now, now iam out
    > >>of ideas what to do
    > >>basically iam planning a tab control in which page developers can define
    > >>tab abd tabelements on the page, and i can render a table with one row
    > >>being link buttons and second row with tabelements..
    > >>
    > >>tha markup of the control looks like
    > >>
    > >> <uc:TabStrip ID="tbMatrixProduct" runat="server">
    > >> <uc:TabElement ID="teGeneral" runat="server" Description="General">
    > >> <uc:GeneralProduct ID="GeneralProduct1" runat="server" />
    > >>
    > >> </uc:TabElement>
    > >> <uc:TabElement ID="teDescription" runat="server"
    > >>Description="Description">
    > >> <uc:productDescription ID="ProductDescription1" runat="server" />
    > >> </uc:TabElement>
    > >> </uc:TabStrip>
    > >>
    > >>i have two controls with tabcontrol having ParseChildren Attribute, and
    > >>having a ControlBuilder defined for TabElement.
    > >>
    > >>The RenderChildControl method looks like
    > >>
    > >>
    > >>protected override void CreateChildControls()
    > >> {
    > >>
    > >> Controls.Clear();
    > >> Table cTable = new Table();
    > >> cTable.ID = "tbl" + this.ID;
    > >>
    > >> cTable.Rows.Add(new TableRow());
    > >> //create link button row and add a link button for each tab
    > >> double width = Math.Floor((double)100 / (Elements.Count+1));
    > >>
    > >> foreach(TabElement element in mElements)
    > >> {
    > >> //create link buttons here
    > >> }
    > >>
    > >> TableCell panelcell = new TableCell();
    > >> panelcell.ColumnSpan = mElements.Count +1 ;
    > >> panelcell.Width = new Unit( "100%");
    > >>
    > >> // create tabelements controls here
    > >> foreach (TabElement element in mElements)
    > >> {
    > >> Panel holder = new Panel();
    > >> holder.ID = "pnl" + element.ID;
    > >> holder.Controls.Add(element);
    > >> holder.Visible = (VisibleTabId == element.ID);
    > >> panelcell.Controls.Add(holder);
    > >> }
    > >>
    > >>
    > >>so far so good, everything comes up just fine, but one of the
    > >>usercontrols in tabelements is having nested datalist..., thats where
    > >>thr trouble begins...
    > >>
    > >>the child datalist is having link buttons, and their event handlers
    > >>never get called ...
    > >>
    > >>I can put the user control on the page and it works fine, but when i put
    > >>it on my TabControl, it stops firing events...
    > >>
    > >>I have tried wiring up events on the markup, in the code behind
    > >>everywhere, but the events dont get called.
    > >>
    > >>
    > >>I can confirm that the usercontrol is not loading the entire datalists
    > >>on the post back, but i dont know why, and how can i make it..., i can
    > >>post the whole code if someone is interested in looking at the problem...
    > >>
    > >>thanks
    > >>
    > >>

    >
    , May 23, 2006
    #4
    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. sleigh
    Replies:
    1
    Views:
    2,672
    sleigh
    Feb 12, 2004
  2. debartsa

    Composite Control not receiving DataGrid (child control) events?

    debartsa, Apr 19, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    181
    debartsa
    Apr 19, 2004
  3. Chad
    Replies:
    0
    Views:
    209
  4. Ian

    Losing Postback state with composite controls

    Ian, Jun 9, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    124
  5. Jason C
    Replies:
    4
    Views:
    670
    Morty Abzug
    Jun 26, 2012
Loading...

Share This Page