ScriptManager run script immediately

孤街醉人 提交于 2019-12-22 09:49:09

问题


I have an update panel load a user control, and the goal here is to have a specific JavaScript function called when this occurred. I was thinking this would be done through the Script Manager, though this does not need to be the case if there's an html alternative.

The flow is basically the following:

  • User clicks button
  • Update panel loads control
  • Javascript function is called

Many thanks

I've already tried RegisterStartupScript(..), though i may have made a syntactical mistake

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);
}   

Solution:

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:


Use

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

Documentation here.



来源:https://stackoverflow.com/questions/1526313/scriptmanager-run-script-immediately

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!