Buttons Disappear

7 posts, 0 answers
  1. Ed Tischofer
    Ed Tischofer avatar
    10 posts
    Member since:
    Jun 2009

    Posted 14 Aug 2008 Link to this post

    I am trying to add buttons dynamically in the code-behind using the Insert method to a toolbar that already has buttons, which were added in the ASP.  When the toolbar renders for the first time, the toolbar looks exactly as I would expect.  However, when a postback occurs, the buttons that were added in the ASP do not show up, but the dynamic buttons do.

    Does the Insert method not really work on postbacks?

    I tried the same scenario, but instead I used the Add method.  Everything works fine in that instance.

    I did notice that it appeared that the toolbar was rendered with the UL and LI tags for the buttons that were not displaying, but the text was not set.

    Any help will be much appreciated.
  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 15 Aug 2008 Link to this post

    Hi Chris,

    I'm afraid I'm missing something. Please, find attached a small page I just prepared. It demonstrates the creation of items with the client-side insert method. Can you please, check it and let me know what am I missing?

    Best regards,
    Erjan Gavalji
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ed Tischofer
    Ed Tischofer avatar
    10 posts
    Member since:
    Jun 2009

    Posted 18 Aug 2008 Link to this post

    Actually, that demo does not portray the scenario that I was trying to describe.  Here is the code that I am using, which is causing buttons to disappear that were displayed initially.

    ASPX:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="DynamicToolbarAdd._Default" %> 
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server">  
    <title>Untitled Page</title> 
    </head> 
    <body> 
    <form id="form1" runat="server">  
    <asp:ScriptManager ID="RadScriptManager1" runat="server"></asp:ScriptManager> 
    <div> 
    <asp:Label ID="lblResult" runat="server"></asp:Label> 
    <telerik:radtoolbar id="toolbar" runat="server" autopostback="true" height="34px" enableembeddedskins="true" 
       enableviewstate="true" skin="Default" width="100%">  
       <items> 
          <telerik:radtoolbarbutton commandname="none" group="RECORDS" enableviewstate="true" > 
             <itemtemplate> 
                <span class="bold">  
                   <asp:literal id="litRECORDS" runat="server" text="RECORDS" enableviewstate="true"></asp:literal> 
                </span> 
             </itemtemplate> 
          </telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton causesvalidation="false" commandname="search" group="RECORDS" 
             text="SEARCH" tooltip="SEARCH"></telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton causesvalidation="false" commandname="insert" group="RECORDS" 
             text="INSERT" tooltip="INSERT"></telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton causesvalidation="false" commandname="copy" group="RECORDS" 
             text="COPY" tooltip="COPY"></telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton causesvalidation="false" commandname="deleteselected" group="RECORDS" 
             text="DELETESELECTED" tooltip="DELETESELECTED"></telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton group="RECORDS" isseparator="true"></telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton commandname="none" group="QUERY" text="QUERY">  
             <itemtemplate> 
                <span class="bold">  
                   <asp:literal id="litQUERY" runat="server" text="QUERY"></asp:literal> 
                </span> 
             </itemtemplate> 
          </telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton commandname="none" group="QUERY" enableviewstate="true">  
             <itemtemplate> 
                <telerik:radcombobox id="cboSavedQueries" runat="server" allowcustomtext="true" autopostback="true" 
                   dropdownwidth="250px" enableembeddedskins="true" height="190px" highlighttemplateditems="true" 
                   markfirstmatch="true" skin="Default" tabindex="3" width="200px"></telerik:radcombobox> 
             </itemtemplate> 
          </telerik:radtoolbarbutton> 
          <telerik:radtoolbardropdown text="SAVE">  
             <buttons> 
                <telerik:radtoolbarbutton accesskey="U" commandname="savequery1" text="SAVEASUSER" value="U"></telerik:radtoolbarbutton> 
                <telerik:radtoolbarbutton accesskey="G" commandname="savequery" text="SAVEASGLOBAL" value="G"></telerik:radtoolbarbutton> 
             </buttons> 
          </telerik:radtoolbardropdown> 
          <telerik:radtoolbarbutton causesvalidation="false" commandname="deletequery" group="QUERY" 
             text="DELETE" tooltip="DELETEQUERY"></telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton causesvalidation="false" commandname="clearquery" group="QUERY" 
             text="CLEAR" tooltip="CLEARQUERY"></telerik:radtoolbarbutton> 
          <telerik:radtoolbarbutton group="QUERY" isseparator="true"></telerik:radtoolbarbutton> 
       </items> 
    </telerik:radtoolbar> 
    </div> 
    </form> 
    </body> 
    </html> 

    CS:

    namespace DynamicToolbarAdd  
    {  
       public partial class _Default : System.Web.UI.Page  
       {  
           protected void Page_Load(object sender, EventArgs e)  
           {  
             RadToolBarButton btn;  
     
             if (!IsPostBack)  
             {  
                btn = new RadToolBarButton("Dynamic1");  
                toolbar.Items.Insert(5, btn);  
     
                btn = new RadToolBarButton("Dynamic2");  
                toolbar.Items.Insert(12, btn);  
             }  
     
             btn = (RadToolBarButton) toolbar.FindButtonByCommandName("insert");  
             btn.Visible = false;  
     
             btn = (RadToolBarButton) toolbar.FindButtonByCommandName("copy");  
             btn.Visible = false;  
     
             btn = (RadToolBarButton) toolbar.FindButtonByCommandName("deleteselected");  
             btn.Visible = false;  
          }  
       }  

     

  5. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 20 Aug 2008 Link to this post

    Hello Chris,

    Thank you for sending a sample code. I have replicated the problem. Now our developers will investigate it further.

    Regards,
    Peter
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 25 Aug 2008 Link to this post

    Hi Chris,

    The scenario you reported is not supported by design. This relates to specifics in the ASP.NET ViewState management - the child controls of templated items in collections modified by the insertion of other children to some location get lost. My suggestion is that you declare the Dynamic1 and Dynamic2 controls to the RadToolBar instance and use their Visible property to show/hide instead.

    Kind regards,
    Erjan Gavalji
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Ed Tischofer
    Ed Tischofer avatar
    10 posts
    Member since:
    Jun 2009

    Posted 25 Aug 2008 Link to this post

    Erjan:

    Thank you for your reply.  Unfortunately, that will not work for my specific application scenario.  The toolbar is part of a master page used within my application.  The toolbar is available to other page developers using the master page, and they need the ability to dynamically add buttons to the toolbar to meet their page's needs.

    I tried using the toolbar with ViewState disabled, but that poses problems with handling toolbar button clicks when not all buttons are visible.  I find that when some buttons are not visible, the client-side event handlers correctly send the button clicked, but the server-side does not.

    The problem is that the client-side determines the position of the button based on the buttons visible; whereas, the server-side determines the position of the button based on the number of buttons added to the toolbar.  This seems wrong.  Both should match so that there are no issues like the one I am experiencing.

    By the way, this was working fine 'RadControls for ASP.NET Classic'.

    Thank you,

    Chris
  8. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 26 Aug 2008 Link to this post

    Hi Chris,

    Indeed, your scenario is not a simple one. The workaround here is to create the templated items on the server, like in the page I'm attaching (by modifying the Controls collection of the button). Let me know if that fits your needs.

    Best regards,
    Erjan Gavalji
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017