2014-12-22 67 views
0

當用戶點擊按鈕Button1時,我怎樣稱呼Button1_Click調用C#代碼隱藏功能,當我點擊按鈕時div會顯示

protected void Button1_Click(object sender, EventArgs e) 
{ 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "id", "show(showdivslowly)", true); 
} 


<!-- language: lang-html --> 
<div id="showdivslowly" runat="server" style="width: 500px; height: 200px; background-color: Blue; display: none">Welcome</div> 
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
+0

它現在沒有? – Icepickle

+1

你目前所擁有的東西有點愚蠢。它會做回發到服務器,然後處理服務器端點擊事件併發送JavaScript到瀏覽器,當響應返回時將運行JavaScript。您可能需要像'OnClientClick =「show(showdivslowly)」''這樣的東西來避免請求/響應往返。 –

+0

請參閱[「應該在其標題中包含」標籤「?」](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles),其中共識是「不,他們不應該」! –

回答

0

嘗試,

protected void Button1_Click(object sender, EventArgs e) 
{ 
    string script = "show(showdivslowly);"; 
    ClientScript.RegisterClientScriptBlock(this.GetType(), "Show", script, true); 
} 

使用的RegisterClientScriptBlock代替的RegisterStartupScript方法。

相關問題