[펌] How to call client-side Javascript function after an UpdatePanel asychronous (Ajax) request is over
.NET/ASP.NET 2009. 9. 30. 20:38출처 : http://zeemalik.wordpress.com/2007/11/27/how-to-call-client-side-javascript-function-after-an-updatepanel-asychronous-ajax-request-is-over/
How to call client-side Javascript function after an UpdatePanel asychronous (Ajax) request is over
Posted by zeemalik on November 27, 2007
If you are using AJAX then the only way i have found yet to give an alert to a user on return to the Asynchronous post back is to add an “end request” handler to the PageRequestManager.
In this way you can tell the request manager to run a javascript function on returning from a Asynchronous post back event of AJAX.
Code for doing this is :
function load()
{
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}
where “EndRequestHandler” will be the name of your javascript function you want to call.
Call the above function in Onload event of <body> tag:
<body onload=”load()”>
function EndRequestHandler()
{
alert(”You record has been saved successfully”);
}
Now If you want to give a different message based on your logic in server side code (code behind) then you can use a server side Hidden Field:
<input id=”hdnValue” type=”hidden” runat=”server” value=”" />
Set its value in server side code on Asychronous Post Back:
Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreateSample.Click
If condition Then
hdnValue.value = “do this”
Else
hdnValue.value = “do that”
End If
End Sub
Now you can check the value of this Hidden Field in your Client Side EndRequestHandler function and give a different alert to user based on its value:
function EndRequestHandler()
{
if (document.getElementById(’<%= hdnValue.ClientID %>’).value == “do this”)
{
alert(”You record has been saved successfully”);
}
else
{
alert(”There is an error”);
}
}
'.NET > ASP.NET' 카테고리의 다른 글
퓨전 차트.... Free Licence... (0) | 2010.03.11 |
---|---|
aspnet request processing cycle (0) | 2010.02.02 |
[펌] Warning the User when Caps Lock is On (0) | 2009.09.29 |
[펌] 동적으로 웹 서버 컨트롤 템플릿 만들기 (0) | 2009.09.29 |
닷넷 웹서비스 에서 WebLogic WebService Call 시 Connection 끊기는 문제... (0) | 2008.08.25 |