显示无/删除样式asp.net code后面不工作 [英] display none / remove style for asp.net code behind not working

查看:118
本文介绍了显示无/删除样式asp.net code后面不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,我的网页上code后面我这样做:

I've got a button on my page in code behind I do this:

btnSaveLineItems.Style.Add(显示,无);

但后来我想表明该按钮所以我尝试这样的:

But later I want to show that button so I tried this:

btnSaveLineItems.Style.Clear();

这并不似乎重新显示该按钮...
在开始的HTML标记有一个样式=显示:无;在页的开头..
并认为风格,即使我尝试将其删除?

This doesnt appear to reshow the button... The html markup in the beginning has a "style=display:none;" in the beginning of the page.. and it maintains that style even though I try to remove it?

任何人都可以在这方面帮助...

Can anyone help with this...

在我的网页第一次启动时我有这样的:

When my page first starts up I have this:

btnSaveLineItems.Style [显示] =无;

这使得像HTML如下:

This renders like the following in HTML:

<?保存更改输入类型=提交名称=$ ctl00 $日程地址搜索Maincontent btnSaveLineItemsVALUE =保存ID =MainContent_btnSaveLineItems称号=风格=边框颜色:#4B6C9E;边框样式:固体;显示:无; />

然后,一个事件发生(选择指数改变了下拉框的事件),我再这样做:

Then an event happens (selected index changed event of a drop down box) where I then do this:

btnSaveLineItems.Style [显示] =;

我也试过:

btnSaveLineItems.Style [显示] =块;

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

和双方呈现相同的HTML:

and both render the same HTML:

<?保存更改输入类型=提交名称=$ ctl00 $日程地址搜索Maincontent btnSaveLineItemsVALUE =保存ID =MainContent_btnSaveLineItems称号=风格=边框颜色:#4B6C9E;边框样式:固体;显示:无; />

推荐答案

您可以删除该样式是这样的:

You can remove that style in this way:

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

btnSaveLineItems.Style.Remove("display");

修改

对于我这种不工作要么...我不知道这是因为降
  下拉列表框是一个更新面板内,这个按钮是外
  在UpdatePanel的?

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 的默认情况下异步回发的内容。最简单的是把你的按钮在另一个的UpdatePanel 并添加的DropDownList AsyncPostBackTrigger

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>

这篇关于显示无/删除样式asp.net code后面不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆