Hiding ASP Button from code behind

4 posts, 0 answers
  1. Pradeep Enugala
    Pradeep Enugala avatar
    55 posts
    Member since:
    Apr 2010

    Posted 12 May 2010 Link to this post

       I have a requirement to show/hide a button. But when I tried to hide the button from C# code behind page. Still a small rectangle is displayed on the screen. below is the code for that.


    But it still displays small rectangular box. This is happening when I include FormDecorator in my page. When I looked at the style of that rectangular box using ie developer tool I see a style rfdSkinnedButton. how can I achieve this. I have to use Form decorator in my master page.
    Please help me on this ASAP.

    Thanks in advance.

  2. Petio Petkov
    Petio Petkov avatar
    825 posts

    Posted 13 May 2010 Link to this post

    Hi Pradeep,

    You should  use CssClass to hide the button, and RadFormDecorator will not decorate it, e.g.
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head id="Head1" runat="server">
        <style type="text/css">
                display: none;
        <form id="form1" runat="server">
       <asp:ScriptManager ID="ScriptManager1" runat="server">
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" />
        someText<asp:Button ID="btn_Cancel" Text="btn_Cancel" runat="server" CssClass="hiddenClass" />someText

    Kind regards,
    Petio Petkov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Patrick
    Patrick avatar
    1 posts
    Member since:
    Sep 2013

    Posted 05 Mar 2014 in reply to Petio Petkov Link to this post

    This works great for hiding the button. But, what do you do when you want to unhide it and re-apply the FormDecorator's style?
  4. Danail Vasilev
    Danail Vasilev avatar
    1502 posts

    Posted 10 Mar 2014 Link to this post

    Hello Patrick,

    You can add the CssClass that hides the button when the button is hidden and set an empty CssClass to the button when it is displayed. For example:
    <style type="text/css">
        .hiddenClass {
            display: none;

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            function OnClientClicked(sender, args) {
                var decBtn = $get("<%=Button1.ClientID%>");
                var hf = $get("<%=hf1.ClientID%>");
                if (decBtn.style.visibility == "hidden") {
                    hf.value = "";
                else {
                    hf.value = "hidden";

    <telerik:RadButton ID="RadButton1" runat="server" Text="Toggle Button Visibility" OnClientClicked="OnClientClicked" OnClick="RadButton1_Click" />
    <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" />
    <asp:HiddenField ID="hf1" runat="server" />
    <asp:Button ID="Button1" Text="decorated button" runat="server"/>
    protected void RadButton1_Click(object sender, EventArgs e)
        if (hf1.Value == "hidden")
            Button1.Attributes["style"] = "visibility:hidden;display:none";
            Button1.CssClass = "hiddenClass";
            Button1.Attributes["style"] = "";
            Button1.CssClass = "";

    Danail Vasilev
    Explore the entire set of ASP.NET AJAX controls we offer here and browse the myriad online demos to learn more about the components and the features they incorporate.
Back to Top