ScriptManager runs the script immediately

My update panel loads a user control, and the goal here is to assign a specific JavaScript function when this happens. I thought this would be done through the Script Manager, although this is not necessary if there is an alternative to html.

The stream is basically the following:

  • User presses a button
  • Update control panel settings
  • Javascript function is called

Many thanks

I already tried RegisterStartupScript(..), although maybe I made a syntax error

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

Decision:

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);
}   
+3
source share
1 answer

Use

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

The documentation is here .

+3
source

Source: https://habr.com/ru/post/1719404/


All Articles