在ASP.Net Microsoft AJAX之后执行JQuery

我试图在ASP.Net Microsoft AJAX发布后回复执行JQuery。

当用户单击链接时,Microsoft AJAX用于更新数据库中的某些字段,如果成功,则会显示标签,通知用户已进行更改。 不幸的是标签不是很明显,我想用它来淡化背景从红色到白色。

问题是当标签上设置visible = false时,生成的html不包含标签(span)。 有没有人知道如何在ASP.Net Microsoft AJAX回发后执行JQuery,或者其他解决方案实现相同的效果?

这是在ASP.NET Ajax回发后执行随机javascript的方法

function executeThis(){ //code here to fade in out the label that comes var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.remove_pageLoaded(executeThis); //job done, remove this so that it is not fired again. } $("link").click(function(){ var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_pageLoaded(executeThis); //this will register executeThis function with MS Ajax libraries which will fire it after next posback //the post back happens here. }); 

你可以在回发中试试这个

ScriptManager.RegisterStartupScript(Me.Form, Me.GetType(), "FunctionName", "FunctionName();", True)

这将在回发完成后调用javascript函数FunctionName()

排序与@Nikhil所说的相同,非常相似,我总是使用:

 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(functionName) 

其中functionName是包含您想要调用的内容的函数的名称。 这确保了每次重新加载/刷新页面/面板时都会调用该函数。

这里有一些伪代码可以让你前进:

  1. 如果没有成功,请保持asp:Label visible property = true但是给它一个显示设置为none的CSS类
  2. 在页面加载时,执行以下命令:

    ScriptManager.RegisterStartupScript(Me.Form,Me.GetType(),“ShowError”,“ShowError();”,True);

  3. 在您的Javascript中,添加以下内容:

    function ShowError(){$(’#myLabelID’)。show()。fadeOut(); }