In that page, click Refresh button, after the click u will see a cancel link, and if u click the cancel the page aborts the async post back !
My problem is, as soon as i start using any session variables on the page_load or on the call back method , the cancel button action [which aborts the async post back!]
no longer works ! Just for reference i said, on page_load, but on any of those page methods, if i start using, say, session["Test"] = "123"; the cancel action no longer works !!
Nilesh,
It doesn't matter -- If (! this.IsPostBack && ! this.IsCallBack ) { --} I tried all combinations, as soon as i use any session variables, any where on the page, the cancel action
PS: If you are trying to cancel an operation. It should be atomic. For example you are setting session state and cancel the operation before processing further. This will result in unwanted results.
I don't understand what you mean by "the cancel button no longer works." What do you expect the button to do that it's not doing? When I use the sample, the visible effect of pressing the cancel button is that that panel disappears. Is that what's no longer
working?
Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
Nevermind, I recreated the sample on my machine so I could see what was going on.
What's happening is that using Session variables means that only one request to the page can be handled at a time. This is because the server acquires a session lock to avoid contention issues.
The "cancel" button in the sample does two things. First, it cancels the current async postback (which really just means that the client ignores the result... there's no way to stop the server from doing its work), and then it starts a new async
postback which hides the alert.
The second postback has to wait for the first one to complete because of the session locking I described above. So the postback is getting canceled right away; it's the second postback that's being delayed.
A better implementation than what's in the sample would have been to hide the alert on the client so that it disappears right away when you cancel the async postback. The next one would still take extra long (waiting for the server to finish its work from
the previous one), but it would be less confusing to the user.
Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
Thanks Steve, for understanding my problem ! clarification : what i meant when i say cancelling postback is i cannot execute any other action from client until the first
call completes [as u said it is because of session lock]. so i went and modified the code like this..
Now the session code never executes [so no locking] while the Async call is going on (NewsClick_Handler for 10 sec) but still I'm not able to cancel the postback, the clicking of cancel
waits until the 10 sec wait is over ! But if i remove the Session line it beautiful works ! One more point that i observed [in the original sample, without session] is,
even if i cancel the async post back from client and perform another action [like moving to anther page] the original call back completes, and that is the exact senario i was looking,
kind of fire & forgot.
Thanks for all your help, let me know if u can somehow find a magic situation where i can use the session without affecting Async actions !
Varadhg
Member
62 Points
24 Posts
Cancelling Async post back
Feb 22, 2007 01:46 AM|LINK
Hi,
From the quickstart tutorials, Cancelling an Async Post Back
http://ajax.asp.net/docs/ViewSample.aspx?sref=UpdatePanelTutorial17/cs/CancelPostback.js
Works fine as it is, but if i add a Session variable in the Default.aspx page_load, i can no longer cancel the
Async post back from client ? means it cancells only after the first call returns !jhj
Pls Help
Thx,
Gopi
"async process"
NileshDesh
Participant
752 Points
186 Posts
Re: Cancelling Async post back
Feb 22, 2007 03:03 AM|LINK
MCP, MCAD.Net, MCSD.Net, SCJP
Future is here, it's just not widely distributed yet.
Varadhg
Member
62 Points
24 Posts
Re: Cancelling Async post back
Feb 22, 2007 11:16 AM|LINK
It is the exact code that the tutorial has here [http://ajax.asp.net/docs/ViewSample.aspx?sref=UpdatePanelTutorial17/cs/default.aspx]
in the page_load event i added,
protected void Page_Load(object sender, EventArgs e)
{
Session["Test"] = "123"; // Line added by me !
if (!IsPostBack)
{
HeadlineList.DataSource = GetHeadlines();
HeadlineList.DataBind();
}
}
After adding that session line, when i press refresh button, a small cancel button is visible to cancel the async postback !
It no longer cancels with that added line, but if u remove that Line, it works magically ! So something with session variables and call back !?
Thx,
Gopi
"async process"
NileshDesh
Participant
752 Points
186 Posts
Re: Cancelling Async post back
Feb 23, 2007 02:27 AM|LINK
You don't need to set Session variable everytime Page is posted back. Change your code as follows and see if it works:
If (! this.IsPostBack && ! this.IsCallBack ) {
Session["Test"] = "123";
}
MCP, MCAD.Net, MCSD.Net, SCJP
Future is here, it's just not widely distributed yet.
Steve Marx
Contributor
2460 Points
643 Posts
Re: Cancelling Async post back
Feb 23, 2007 02:35 AM|LINK
What exactly do you mean "it cancels only after the first call returns"? (What's different between the Session version and the non-Session version?)
Varadhg
Member
62 Points
24 Posts
Re: Cancelling Async post back
Feb 23, 2007 02:50 AM|LINK
Steve,
You have run this tutorial to see what i meant ! here is the url : http://ajax.asp.net/docs/Samples/UpdatePanelTutorial17/cs/Default.aspx
and here is the original tutorial : http://ajax.asp.net/docs/tutorials/CancelAsyncPostback.aspx
In that page, click Refresh button, after the click u will see a cancel link, and if u click the cancel the page aborts the async post back !
My problem is, as soon as i start using any session variables on the page_load or on the call back method , the cancel button action [which aborts the async post back!]
no longer works ! Just for reference i said, on page_load, but on any of those page methods, if i start using, say, session["Test"] = "123"; the cancel action no longer works !!
Nilesh,
It doesn't matter -- If (! this.IsPostBack && ! this.IsCallBack ) { --} I tried all combinations, as soon as i use any session variables, any where on the page, the cancel action
stops working !
Defenetly there is something wrong here !! :)
Thx,
Gopi
"async process"
NileshDesh
Participant
752 Points
186 Posts
Re: Cancelling Async post back
Feb 23, 2007 03:16 AM|LINK
Are you checking whether AsyncPostBack is still underway? What if postback already is been processed?
Take a look at this tutorial where it checks status of Asynchronous postback before trying to cancel it.
http://ajax.asp.net/docs/tutorials/CancelAsyncPostback.aspx
PS: If you are trying to cancel an operation. It should be atomic. For example you are setting session state and cancel the operation before processing further. This will result in unwanted results.
MCP, MCAD.Net, MCSD.Net, SCJP
Future is here, it's just not widely distributed yet.
Steve Marx
Contributor
2460 Points
643 Posts
Re: Cancelling Async post back
Feb 23, 2007 03:33 AM|LINK
Steve Marx
Contributor
2460 Points
643 Posts
Re: Cancelling Async post back
Feb 23, 2007 03:50 AM|LINK
Nevermind, I recreated the sample on my machine so I could see what was going on.
What's happening is that using Session variables means that only one request to the page can be handled at a time. This is because the server acquires a session lock to avoid contention issues.
The "cancel" button in the sample does two things. First, it cancels the current async postback (which really just means that the client ignores the result... there's no way to stop the server from doing its work), and then it starts a new async postback which hides the alert.
The second postback has to wait for the first one to complete because of the session locking I described above. So the postback is getting canceled right away; it's the second postback that's being delayed.
A better implementation than what's in the sample would have been to hide the alert on the client so that it disappears right away when you cancel the async postback. The next one would still take extra long (waiting for the server to finish its work from the previous one), but it would be less confusing to the user.
Varadhg
Member
62 Points
24 Posts
Re: Cancelling Async post back
Feb 23, 2007 11:10 AM|LINK
Thanks Steve, for understanding my problem ! clarification : what i meant when i say cancelling postback is i cannot execute any other action from client until the first
call completes [as u said it is because of session lock]. so i went and modified the code like this..
if
(!IsPostBack && !IsCallback && !ScriptManager1.IsInAsyncPostBack){ HttpContext.Current.Session["test"] = "adfasd";HeadlineList.DataSource = GetHeadlines();
HeadlineList.DataBind();
}
protected
void NewsClick_Handler(object sender, EventArgs e){System.Threading.Thread.Sleep(10000);
HeadlineList.DataSource = GetHeadlines();
HeadlineList.DataBind();
}
Now the session code never executes [so no locking] while the Async call is going on (NewsClick_Handler for 10 sec) but still I'm not able to cancel the postback, the clicking of cancel
waits until the 10 sec wait is over ! But if i remove the Session line it beautiful works ! One more point that i observed [in the original sample, without session] is,
even if i cancel the async post back from client and perform another action [like moving to anther page] the original call back completes, and that is the exact senario i was looking,
kind of fire & forgot.
Thanks for all your help, let me know if u can somehow find a magic situation where i can use the session without affecting Async actions !
Gopi
"async process"