2012-06-20 31 views
10

我有一個按鈕,我的網頁上在後面的代碼我這樣做:顯示無/刪除樣式asp.net後面的代碼不工作

btnSaveLineItems.Style.Add("display", "none");

但後來我想顯示按鈕,我嘗試這樣做:

btnSaveLineItems.Style.Clear();

,這並不似乎重新顯示按鈕... 在開始的HTML標記有一個「樣式=顯示:無;」在頁面的開始處.. 並且即使我嘗試刪除它,它仍保留該樣式?

任何人都可以在這方面幫助...

當我的頁面第一次啓動時我有這樣的:

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 [ 「顯示」] = 「塊」;

兩者呈現相同的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;" />

+1

+1。必須從這個查詢中學到一些新東西。 – Pankaj

回答

9

您可以刪除此方式,風格:

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

btnSaveLineItems.Style.Remove("display"); 

編輯

這對我來說不適用...不知道是不是因爲下降 下拉列表框在更新面板裏面,而這個按鈕不在更新面板的 之內?

是的,您只能在默認情況下更新異步回發中當前的UpdatePanel的內容。最簡單的是把你的按鈕在另一個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> 
+0

這不適用於我...我不知道是否因爲下拉列表框在更新面板內,並且此按鈕不在updatepanel中? – oJM86o

+2

你給的第一行不能是有效的javascript – Esailija

+1

我已經試過這兩個... – oJM86o

1
btnSaveLineItems.Style["display"] = "block"; 
+0

這沒有幫助... – oJM86o

+0

這是一個測試代碼。當你需要顯示'Button'時,將'display'屬性設置爲'block'。這就是它:) – Pankaj

+0

沒有那個不是,呈現的HTML出來作爲''我調試了我的代碼。 – oJM86o

1

這個工程:

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

添加的風格

gv.Style.Remove("top"); 

刪除樣式

相關問題