【问题标题】:How do I run client script after a postback?回发后如何运行客户端脚本?
【发布时间】:2008-11-26 04:42:28
【问题描述】:

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

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

【问题讨论】:

  • 您希望它在 Page_Load 或按钮点击事件上调用吗?

标签: asp.net ajax


【解决方案1】:

如果您使用的是 ASP.NET AJAX,您可以尝试以下方法:

页面加载时必须调用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
}

这是基于Disturbed Budda的代码

【讨论】:

    猜你喜欢
    • 2019-08-14
    • 1970-01-01
    • 2011-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 2020-06-06
    相关资源
    最近更新 更多