如何在回发后运行客户端脚本?

时间:2022-01-10 01:24:09

I'm looking for something like OnClientClick for a button, but I want it to happen after the postback (instead of before). I'm currently using the following, which works, but it adds the script block over and over again, which is not what I want. I simply want to execute an existing client script function.

我正在寻找像OnClientClick这样的按钮,但我希​​望它发生在回发之后(而不是之前)。我目前正在使用以下功能,但它会一遍又一遍地添加脚本块,这不是我想要的。我只想执行现有的客户端脚本函数。

ScriptManager.RegisterClientScriptBlock( 
  this, 
  typeof( MyList ), 
  "blah", 
  "DraggifyLists();", 
  true );

1 个解决方案

#1


1  

If you're using ASP.NET AJAX, you could try the following:

如果您使用的是ASP.NET AJAX,则可以尝试以下操作:

addRequestHandler() must be called when your page loads

页面加载时必须调用addRequestHandler()

function addRequestHandler()
{
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}


function endRequestHandler(sender, args)
{
    // This function will be called after the postback has completed

    // add your JavaScript function call here
}

This is based on code from Disturbed Budda

这是基于Disturbed Budda的代码

#1


1  

If you're using ASP.NET AJAX, you could try the following:

如果您使用的是ASP.NET AJAX,则可以尝试以下操作:

addRequestHandler() must be called when your page loads

页面加载时必须调用addRequestHandler()

function addRequestHandler()
{
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}


function endRequestHandler(sender, args)
{
    // This function will be called after the postback has completed

    // add your JavaScript function call here
}

This is based on code from Disturbed Budda

这是基于Disturbed Budda的代码