我的页面上有一个按钮,后面的代码是这样做的: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
中并添加 DropDownList
如 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>
关于c# - 显示无/删除样式背后的asp.net 代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11125609/