Execute JQuery after ASP.Net Microsoft AJAX

孤者浪人 提交于 2020-01-03 01:58:23

问题


I'm trying to execute JQuery after an ASP.Net Microsoft AJAX post back.

When a user clicks on a link, Microsoft AJAX is used to update some fields in the DB and if success a label appears informing the user the change has been made. Unfortunately the label is not very obvious and I would like to use to fade the background from red to white.

The problem is that when visible=false is set on the label, the resulting html does not include the label(span). Does anyone know how to execute JQuery after an ASP.Net Microsoft AJAX post back, or another solution to achieve the same affect?


回答1:


This is how you can execute a random javascript after an ASP.NET Ajax postback

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



回答2:


You could try this in the postback

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

This will call the javascript function FunctionName() sfter the postback is complete




回答3:


Sort of the same as what @Nikhil has said, something very similiar and what I always use:

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

Where functionName is the name of the function containing whatever you want called. This ensures that the function is called whenever the page/panel is reloaded/refreshed.




回答4:


Here is a bit of pseudocode to get you going:

  1. If no success, keep the asp:Label visible property = true but give it a CSS class with display set to none
  2. On page load, execute the following:

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

  3. In your Javascript, add the following:

    function ShowError() { $('#myLabelID').show().fadeOut(); }



来源:https://stackoverflow.com/questions/6254769/execute-jquery-after-asp-net-microsoft-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!