c# - 显示无/删除样式背后的asp.net 代码不起作用

标签 c# css asp.net

我的页面上有一个按钮,后面的代码是这样做的:
btnSaveLineItems.Style.Add("display", "none");
但后来我想显示那个按钮,所以我尝试了这个:
btnSaveLineItems.Style.Clear();
这似乎没有重新显示按钮......
开头的 html 标记有一个“style=display:none;”在页面的开头..
即使我试图删除它,它也保持这种风格?

当我的页面第一次启动时,我有这个:
btnSaveLineItems.Style["display"] = "none";
这在 HTML 中呈现如下:
<input type="submit" name="ctl00$MainContent$btnSaveLineItems" value="Save" id="MainContent_btnSaveLineItems" title="Save changes?" style="border-color:#4B6C9E;border-style:Solid;display:none;" />
然后发生一个事件(下拉框的选定索引更改事件),然后我执行以下操作:
btnSaveLineItems.Style["display"] = "";
我也试过:
btnSaveLineItems.Style["display"] = "block";
并且都呈现相同的 HTML:
<input type="submit" name="ctl00$MainContent$btnSaveLineItems" value="Save" id="MainContent_btnSaveLineItems" title="Save changes?" style="border-color:#4B6C9E;border-style:Solid;display:none;" />

最佳答案

您可以通过以下方式删除该样式:

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


btnSaveLineItems.Style.Remove("display");

编辑 :

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?



是的,只能更新当前UpdatePanel的内容默认情况下在异步回发中。最简单的方法是将您的 Button 放在另一个 UpdatePanel 中并添加 DropDownListAsyncPostBackTrigger :
<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>

关于c# - 显示无/删除样式背后的asp.net 代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11125609/

相关文章:

c# - 选择包含特定属性的所有 xml 节点

html - 通过忽略其他元素将元素置于 div 中居中

css - Bootstrap - 水平对齐下拉列表中的内容,并在它们之间使用垂直分隔符

C#修复语句

c# - ZeroMQ 性能问题

c# - Lambda 不能做 Int16 比较?

html - 将 CSS 选择器与 :first-child 组合

c# - DateTime.Parse或Convert.ToDateTime不起作用

ASP.net 队列长度与应用程序池队列长度

c# - 代码优先配置错误