display none / remove style for asp.net code behind not working

this works :

gv.Style.Add(HtmlTextWriterStyle.Top, "-44px");

to add the style

and

gv.Style.Remove("top");

to remove the style


You can remove that style in this way:

 btnSaveLineItems.Style["display"] = "";

or

btnSaveLineItems.Style.Remove("display");

Edit:

That doesnt work for me either...I wonder if it is because of the drop down list box is inside of an update panel and this button is outside of the updatepanel?

Yes, you can only update the content of the current UpdatePanel in an asynchronous postback by default. The easiest would be to put your Button in another UpdatePanel and add the DropDownList as AsyncPostBackTrigger:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DdlChanged">
        <asp:ListItem Text="Item 1" Value="1"></asp:ListItem>
        <asp:ListItem Text="Item 2" Value="2"></asp:ListItem>
    </asp:DropDownList>
     </ContentTemplate>
    </asp:UpdatePanel>

     <asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <asp:Button ID="btnSaveLineItems" Text="click me" runat="server" />
     </ContentTemplate>
     <Triggers>
        <asp:AsyncPostBackTrigger ControlID="DropDownList1" />
     </Triggers>
    </asp:UpdatePanel>

btnSaveLineItems.Style["display"] = "block";

Tags:

C#

Css

Asp.Net