Skip to content

Variable problem

Jeremy Burbidge

Asked Nov 7, 2007, 1:15 AM EST1 answer
Share
LinkedInX
Hi all

I'm a complete newby to C#, so this should be very simple!

I have a bound datagrid displaying members. There are a number of buttons using the asp:ImageButton for deleting user, etc.

I want to be able to hide a button using css style, but the 'hidden' or 'visble' string should be in a varable.

For example:
<asp:ImageButton ID=ImgBtnDelete Runat=server ImageUrl="../Images/delete.jpg" AlternateText="Delete" CommandName="Delete" CssClass="right_blue_link" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "EmpId")%>' style="visibility: <%=strStyle%>"></asp:ImageButton>

strStyle is being declared ok & populated with the correct string
the style is working when the visibilty is hardcoded

The problem is retrieving the strStyle variable...

Help please?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    there must be some perticular event on which u want to change the visibility of the button.

    what  is that?

    change the visibility when that event occur. like I change the visibility of the image button on the onclick event of checkbox control.

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitled Page</title>

    <script type="text/javascript">

    JavaScript
    function ImgBtnDelete_Init()
    {
    
    var ImgBtnDelete = document.getElementById("ImgBtnDelete")
    if (ImgBtnDelete.style.visibility!="hidden")
    ImgBtnDelete.style.visibility="hidden";
    else
    ImgBtnDelete.style.visibility="visible"
    }

    </script>

    </head>

    <body>

    <form id="form1" runat="server">

    <asp:ImageButton ID="ImgBtnDelete" Runat="server" ImageUrl="../Images/delete.jpg" AlternateText="Delete"></asp:ImageButton>

    <asp:CheckBox ID="chk" runat="server" AutoPostBack="false" onclick="ImgBtnDelete_Init()" />

    </form>

    </body>

    </html>

    0