This is a migrated thread and some comments may be shown as answers.

Buttons Disappear

6 Answers 231 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Ed Tischofer
Top achievements
Rank 1
Ed Tischofer asked on 14 Aug 2008, 08:38 PM
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.

6 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 15 Aug 2008, 06:53 AM
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.
0
Ed Tischofer
Top achievements
Rank 1
answered on 18 Aug 2008, 06:46 PM
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;  
      }  
   }  

 

0
Peter
Telerik team
answered on 20 Aug 2008, 02:58 PM
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.
0
Erjan Gavalji
Telerik team
answered on 25 Aug 2008, 03:54 PM
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.
0
Ed Tischofer
Top achievements
Rank 1
answered on 25 Aug 2008, 04:08 PM
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
0
Erjan Gavalji
Telerik team
answered on 26 Aug 2008, 02:01 PM
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.
Tags
ToolBar
Asked by
Ed Tischofer
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
Ed Tischofer
Top achievements
Rank 1
Peter
Telerik team
Share this question
or