Client side script won’t execute with ScriptManager

  1. I have a user control which has an
    update panel
  2. I am trying to execute a client side
    script from an async postback from a
    button inside the updatepanel
  3. I am using
    ScriptManager.RegisterStartupScript
    to execute the script but it never
    gets executed
  4. The scriptmanager proxy is not
    inside the user control itself it is
    in the page containing the user
    control
  5. Is there any way round this problem?

Script registration:

ScriptManager.RegisterStartupScript(
    this, 
    this.GetType(), 
    "CloseEdit", 
    "CloseEditModal();", 
    true
);

Thanks, Damien.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The documentation to the ScriptManager.RegisterStartupScript Method (Control, Type, String, String, Boolean) (I assume you use this overload) says:

Startup script blocks that are
registered by using this method are
sent to the page only when the control
that is registering the block is
inside an UpdatePanel control that is
being updated.

I assume you call the ScriptManager.RegisterStartupScript method from your user control (which has an update panel as you said). This means the first parameter of the method is not inside an UpdatePanel control that is being updated, so the script block is not registered. So changing your script registraction to:

ScriptManager.RegisterStartupScript(
    btnUpdate, 
    btnUpdate.GetType(), 
    "CloseEdit", 
    "CloseEditModal();", 
    true
);

should solve your problem. btnUpdate here is the button inside you UpdatePanel that caused the postback (you mention this in paragraph 2).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x