Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Abort page execution

Status
Not open for further replies.

choche

Programmer
Joined
May 4, 2010
Messages
3
Location
AR
Hi, i'm trying a code to update a html div using ActiveX or
XMLHttpRequest from client side and a asp.net page that retrieve data.
The asp.net page is a loop for some seconds and then i do it again the
request.

My javascript from client side is like this:

function Tracking(U,M,V){
var a=window.ActiveXObject?new window.ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest;
try{a.open(M,U,true);a.send(V);}catch(c){a=null;alert('Exception: '+c);}return a;
}

var MyRequest=Tracking('async/mypage.aspx?_r'+(Math.random()*999).toString(),'get',null);

function Abort(){MyRequest.abort();}
function ViewRequest(){
/*
Some code
MyRequest.responseText ....
*/
}

And the server side:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim StartDate As Date = Now

While Now.Subtract(StartDate).Seconds < 15
' Response.Write (something)....
Response.Flush()
Response.Clear()
System.Threading.Thread.Sleep(50)
End While

End Sub

Now, when i try abort the page request by client side, i call the function Abort and the request is stopped but mypage.aspx still in
execution to complete the operation for some seconds. How i do it to stop the execution before 15 seconds by client script?
any idea on how I can do this?

Thanks
 
1st. i would use a js library like jquery to manage the ajax infrastructure. not only does it handle browser variances, it's a much cleaner api.

as for stopping the call, you can't. once the http request is sent you cannot stop it. abort will stop the ajax request from waiting for a response.

something else to consider. if this is an ajax call you will not need the entire webforms page life cycle to handle the request. consider using a PageMethod or calling an http handler (ashx). they do not require the overhead of a webform (aspx).

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Thanks Jason for reply to me. I dont knowed "page methods", i'll search the correct
way to implement the same but with ashx.

Thanks again
 
Hi again,

I solved the trouble using Response.IsClientConnected. When it given False I get out loop and that's all

 
nice.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top