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

Hiding ASP Button from code behind

3 Answers 1527 Views
FormDecorator
This is a migrated thread and some comments may be shown as answers.
Pradeep Enugala
Top achievements
Rank 1
Pradeep Enugala asked on 12 May 2010, 06:41 AM
Hi,
   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.

 btn_Cancel.Attributes["style"]="visibility:hidden;display:none";

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.



3 Answers, 1 is accepted

Sort by
0
Petio Petkov
Telerik team
answered on 13 May 2010, 03:19 PM
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">
    <title></title>
  
    <style type="text/css">
        .hiddenClass
        {
            display: none;
            }
    </style>
</head>
<body>
    <form id="form1" runat="server">
   <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        </Scripts>
    </asp:ScriptManager>
    <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" />
    someText<asp:Button ID="btn_Cancel" Text="btn_Cancel" runat="server" CssClass="hiddenClass" />someText
      
    </form>
</body>
</html>



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.
0
Patrick
Top achievements
Rank 1
answered on 06 Mar 2014, 03:47 AM
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?
0
Danail Vasilev
Telerik team
answered on 10 Mar 2014, 11:46 AM
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:
CSS:
<style type="text/css">
    .hiddenClass {
        display: none;
    }
</style>

JavaScript:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script>
        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";
            }
        }
    </script>
</telerik:RadCodeBlock>

ASPX:
<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"/>
C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    if (hf1.Value == "hidden")
    {
        Button1.Attributes["style"] = "visibility:hidden;display:none";
        Button1.CssClass = "hiddenClass";
    }
    else
    {
        Button1.Attributes["style"] = "";
        Button1.CssClass = "";
    }
}



Regards,
Danail Vasilev
Telerik
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.
Tags
FormDecorator
Asked by
Pradeep Enugala
Top achievements
Rank 1
Answers by
Petio Petkov
Telerik team
Patrick
Top achievements
Rank 1
Danail Vasilev
Telerik team
Share this question
or