Client side script won't execute with ScriptManager

后端 未结 1 1918
悲哀的现实
悲哀的现实 2021-01-16 23:12
  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. <
相关标签:
1条回答
  • 2021-01-16 23:45

    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).

    0 讨论(0)
提交回复
热议问题