开发者

Execute JQuery after ASP.Net Microsoft AJAX

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 backgro开发者_StackOverflowund 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?


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


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


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜