2012-12-18 119 views
1

我對OnClick事件Button的這段代碼:運行JavaScript代碼從代碼後面進入的UpdatePanel

if (true) { 
    ClientScript.RegisterStartupScript(UpdatePanel1.GetType(), "", "show_modal('true');", true); 
} else { 
    ClientScript.RegisterStartupScript(UpdatePanel1.GetType(), "", "show_modal();", true); 
} 

我定義按鈕作爲一個UpdatePanel一個TRIGER:

<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="btnEdit" EventName="Click" /> 
</Triggers> 

的功能show_modal位於包含在ASP頁面中的.js文件中。

我該如何使這個腳本有效?

+0

看看:http://stackoverflow.com/questions/3341623/asp-net-updatepanel-in-gridview-jquery-datepicker/3341741#3341741 http://stackoverflow.com/questions/13890391/asp -net-web-application-jquery-photoviewer-and-ajaxical-update/13890462#13890462 http://stackoverflow.com/questions/13856717/jquery-accordion-not-re-initiating-after-an-asp-net-回覆/ 13856997#13856997 – Aristos

+0

任何一個幫助? – Soufiaane

+0

[類似問題](http://stackoverflow.com/questions/2864398/javascript-code-inside-updatepanel) - [其他類似問題](http://stackoverflow.com/questions/487269/registering-a-dynamic -javascript-after-an-updatepanels-update) - [和其他類似的問題](http://stackoverflow.com/questions/7844061/running-javascript-after-update-panel-refresh) – adripanico

回答

2

請勿使用ClientScript.RegisterStartupScript。改爲使用ScriptManager1.RegisterStartupScript。其中「ScriptManager1」是您的ScriptManager控件的名稱。

+1

它不是'ScriptManager1',它只是'ScriptManager'。 'RegisterStartupScript'是'ScriptManager'類的一個共享函數(即:一個類方法,而不是一個實例)。 – adripanico

+0

當你需要編寫一個可以在任何頁面上運行的泛型方法時呢? http://codecorner.galanter.net/2011/03/03/run-javascript-from-both-full-and-partial-asp-net-postback/ –