Custom Templates and server side handling of events

This post has 9 replies

Not Ranked
Posts: 9
closte Posted: Wed Oct 13, 2004 @ 10:02 AM
I have programmatically created a NavBar by the following methods successfully.

In Page Load:

if (!this.Page.IsPostBack)
   {
     this.BuildNavBarTemplates();
     this.BuildNavBar();
   }

In BuildNavBarTemplates:
otemp = new ComponentArt.Web.UI.NavigationCustomTemplate(); 
otemp.ID = "RisksTemplate"; 
otemp.Template = new RisksTemplate();
NavBar.Templates.Add(otemp);

BuildNavBar
ComponentArt.Web.UI.NavBarItem newItem = new ComponentArt.Web.UI.NavBarItem();
      ComponentArt.Web.UI.NavBarItem templatedNode;
      
// Build the 'Risks' NavBar Item...
newItem.Text = "Risks";
newItem.Expanded = false;
newItem.AutoPostBackOnSelect = false;
this.NavBar.Items.Add(newItem);
      
templatedNode = new ComponentArt.Web.UI.NavBarItem();
templatedNode.TemplateId = "RisksTemplate"; 
NavBar.Items[0].Items.Add(templatedNode);

Risk Template Class
public class RisksTemplate:ITemplate
  {
    public void InstantiateIn(System.Web.UI.Control container)
    {         
      Button myBtn = new Button();
      myBtn.ID = "myBtn";
      myBtn.Text = "Button";

      container.Controls.Add(new LiteralControl("<table cellspacing=0 border=0 cellpadding=0>"));
      container.Controls.Add(new LiteralControl("<tr>"));
      container.Controls.Add(new LiteralControl("<td>"));     
      container.Controls.Add(myBtn);
      container.Controls.Add(new LiteralControl("</td>"));
      container.Controls.Add(new LiteralControl("</tr>"));
      container.Controls.Add(new LiteralControl("</table>"));
    } 	    
  }


.. and the event handler..

The button does not appear in my NavBar. The code finds the button in the NavItem fine.

If I omit the handler addition, the button appears fine.

What am I doing wrong.

I will wait for an answer to this one before posting my dropdownlist in a NavItem problems :-)
Top 10 Contributor
Posts: 6,149
stephen Posted: Wed Oct 13, 2004 @ 1:12 PM
Just to keep you updated: there's definitely something strange going on here, and we're investigating this now. Your code seems to be just fine, by the way, and we believe we know what the issue is (it looks like the button in your template is not being added to viewstate), but we're not able to find the source of the problem just yet.

I'll post again when I learn more, and thanks for your patience with this.
Stephen Hatcher, Developer Support Manager
Not Ranked
Posts: 9
closte Posted: Thu Oct 14, 2004 @ 11:08 AM
Is there anyway to call:

RaiseBubbleEvent

From my tempalte class? Will the Nav Bar propogate that upwards to my continer class?
Top 10 Contributor
Posts: 6,149
stephen Posted: Thu Oct 14, 2004 @ 1:22 PM
Honestly, I don't believe this would work- we use our own custom methods for creating and binding templates, and I believe that this event would simply be ignored.
Stephen Hatcher, Developer Support Manager
Not Ranked
Posts: 9
closte Posted: Wed Oct 20, 2004 @ 7:22 AM
Any ETA on this one at all or an update.
Much appreciated....
Top 10 Contributor
Posts: 6,149
stephen Posted: Mon Oct 25, 2004 @ 9:14 AM
I've replied to the support request you opened in regards to this. If you wish to follow up on this, please respond there, as in my experience having the conversation occur in two different areas can be confusing.

Thanks in advance.
Stephen Hatcher, Developer Support Manager
Not Ranked
Posts: 9
closte Posted: Mon Oct 25, 2004 @ 9:29 AM
Thanks for your reply to this.
I will reply to the mail.

Regards
ChrisL
Not Ranked
Posts: 14
asifshiraz Posted: Fri Apr 1, 2005 @ 8:20 AM
Hello

We are experiencing a similar problem, that any server side controls added inside the templates of navbar, fail to work in the way they do outside of the template. They do not show up at all, (object not found), or else fail to handle standard asp.net events like OnItemCommand etc.

You mention here that you have responded to the original poster of this request, but it would be good to have it here also so others can also see it.

Thanks
Asif
Not Ranked
Posts: 9
closte Posted: Fri Apr 1, 2005 @ 9:20 AM
The reply that I had received was that there was problems to be fixed in a later release.

I however managed to get 90% of my controls (even some custom controls) working although viewstate on drop downs is not functioning as expected. I also rebind most if my controls each postback.

Here is a brief summary of what you probably need to know.

Using a template class created the desired layout of your controls. This template class is created passing in a reference to the parent or calling control that contains the NavBar component.

  /// <summary>
  /// My template class
  /// </summary>
  public class DocumentationTemplate:ITemplate
  {
    // The parent control that contains the nav bar control
    private ControlInputControl m_parentControl;
    
    /// <summary>
    /// Simple constructor
    /// </summary>
    /// <param name="_parentControl"></param>
    public DocumentationTemplate(ControlInputControl _parentControl)
    {
      m_parentControl = _parentControl;
    }
    
    /// <summary>
    /// Where all the layout and controls are kept
    /// </summary>
    /// <param name="container"></param>
    public void InstantiateIn(System.Web.UI.Control container)
    {   
    // Create your controls in the parent class and then reference them in here.
    // i.e
      Row = new TableRow();
      Cell = new TableCell();
      Cell.Attributes.Add("Width", "80%");
      Cell.Controls.Add(m_parentControl.myDropDownList);
    }    


Then in the CreateChildControls of the main control containing the NavBar component I do the construction of the DropDown List control (and all other controls that I am using.

The control in my case is created as a member variable of this c

i.e.
    protected override void CreateChildControls() 
    {
      try 
      { 
       myDropDownList = new DropDownList();
       myDropDownList.CssClass = "ControlDropDown";
       myDropDownList.AutoPostBack = true;
       // etc etc


The event handling function is then handled in the parent class rather than the Template class.

I hoep this helps a little. Please post if it does not.....
Regards
Top 25 Contributor
Posts: 179
conet Posted: Mon Nov 8, 2010 @ 6:27 AM
I think I've got the same problem in NavBar with an asp dropdown.
The Selected Value is not persisted after postback. 
CA Grid seems to work and TreeView I don't know yet.
Page 1 of 1 (10 items)