开发者

How to call a javascript function after an async postback

开发者 https://www.devze.com 2023-02-26 15:19 出处:网络
I was using the following script to call a javascript function only if my page in Edit Mode: protected void Page_PreRender(object sender, EventArgs e)

I was using the following script to call a javascript function only if my page in Edit Mode:

protected void Page_PreRender(object sender, EventArgs e)
{
    if (EditMode)
        ClientScript.RegisterStartupScript("".GetType(), 
                                           "EnableSelectableKey", 
                                           "EnableSelectableForRolesLists();",
                                        开发者_如何学JAVA    true);
}

After I added an update panel, the script has not been called.

How to fix the problem?


Using Sys.WebForms.PageRequestManager.endRequest as Dave_Stott says is a cleaner way to do this (if there is such a thing as "clean" when talking about UpdatePanels and client/server interaction). But you can also simply change your code to use ScriptManager instead of ClientScript and it should work:

ScriptManager.RegisterStartupScript("".GetType(), 
                                           "EnableSelectableKey", 
                                           "EnableSelectableForRolesLists();",
                                            true);


Have a look at: http://msdn.microsoft.com/en-us/library/bb383810.aspx

This should point you in the right direction :)

0

精彩评论

暂无评论...
验证码 换一张
取 消