好。我面臨的問題是我有我自己的自定義控件,我做了一個查詢,獲取記錄,並根據數據動態地添加html控件到頁面。動態Javascript在asp.net
現在有我這樣做是有文字對照的幫助下加入一些動態JavaScript
的問題。
<asp:Literal runat="server" ID="latEventToolTipJqueryScripts"></asp:Literal>
這就像一個魅力
<script language="javascript" type="text/javascript">
// <![CDATA[
Sys.Application.add_load(WireEvents_<%=this.ID%>); // fix wiring for .NET ajax updatepanel
$(WireEvents_<%=this.ID%>); // handle page load wiring
function WireEvents_<%=this.ID%>() {
<asp:Literal runat="server" ID="latEventToolTipJqueryScripts"></asp:Literal>
}
// ]]>
</script>
我動態添加文字文本從後面的代碼。
但是,將控件放置到updatepanel時,回發不會更新腳本。
編輯:Sys.Application.add_load
重新引用必要的功能與updatepanel很好。問題在於,需要代替文字的腳本在update面板中不會更新。
我已經嘗試了ClientScript.RegisterStartupScript,但它具有與文字控制技巧相同的效果。任何幫助?
---------------------------已解決(tnx to Pranay Rana)----------- -----------------------
擺脫了ascx方面的字面意思。以及Sys.Application.add_load
現在它只在後面的代碼中。扔掉我的東西是JQuery的東西。
this.strBuilderJS.Append("<script language='javascript' type='text/javascript'>" +
"$(WireEvents_" + this.ID + ");" +
"function WireEvents_" + this.ID + "(){"+
" alert('stuff');");
this.strBuilderJS.Append( "}</script>");
然後
ScriptManager.RegisterStartupScript(this, this.GetType(), "strBuilderJS", strBuilderJS.ToString(), false);
其實這就是我在查看ClientScript.RegisterStartupScript時所看到的頁面,我也嘗試了您的建議ScriptManager.RegisterStartupScript()。它與我在文字控制方面的作用相同。它會在頁面末尾添加腳本,以便在標記之前。它不會做的是在updatepanel中使用控件時更新腳本 – robert 2011-06-02 06:55:38
@robert - 當updatepanle更新頁面時,用於執行綁定腳本的ScriptManager.RegisterScript .... – 2011-06-02 06:58:12