脚本管理器立即执行脚本

3
我有一个更新面板加载了一个用户控件,此处的目标是在发生这种情况时调用特定的JavaScript函数。 我认为可以通过Script Manager来完成,但如果有html替代方案,则不需要这样做。
流程基本如下:
用户单击按钮 更新面板加载控件 调用JavaScript函数
非常感谢。我已经尝试过RegisterStartupScript(..),但可能存在语法错误。
if (show)
{ 
    string scriptId = String.Format("{0}:script", ++uniquePopupId);
    string scriptTag = String.Format("showPopup({0},{1});", Width, Height);
    ScriptManager.RegisterStartupScript(this, this.GetType(), scriptId, scriptTag, true);
}   

解决方案:
if (show)
{ 
    string scriptId = String.Format("{0}:script", ++uniquePopupId);
    string scriptTag = String.Format("showPopup({0},{1});", Width, Height);
    ScriptManager.RegisterStartupScript(updPanelChildControl, updPanelChildControl.GetType(), scriptId, scriptTag, true);
}   
1个回答

3
使用
ScriptManager.RegisterStartupScript(myControlInstance, 
                                    typeof(MyControl),
                                     "key",
                                     "my javascript string here", 
                                     true);

文档在此


我已经尝试过类似的事情,除非你看到我所做的有什么问题。 - Highstead
啊,我一直在错误地使用RegisterStartupScript,感谢提供的文档。 - Highstead

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接