AJAX UpdatePanel - IsInAsyncPostBack and IsPostBack returning false

P

PSY

I have an asp.net webpage.

On that page, there is an update panel with several check boxes in
it. Each of those check boxes has an autopostback="true" attribute
set and a method attached to it that performs some logic on the page.
When one of these events is fired, a partial postback is performed and
the code for that event and the page life cycle events fire
(Page_Init, Page_Load, etc,,,) In my Page_Init and Page_Load blocks,
there is code that should only be executed when the page is first
loaded. Hence, I performed a check for Page.IsPostBack andalso
ScriptManager.GetCurrent(Page).IsInAsyncPostBack during these phases.
Typically, if you click one of these checkboxes, the event fires and
both the IsPostBack and IsInAsyncPostBack values are true, so this
code doesn't execute (Exactly what is desired). However, if you
quickly click on a number of the checkboxes one after another,
eventually you will have your IsPostBack and IsInAsyncPostBack values
become false. I know this, because I have set breakpoints inside of
this section and have examined the values of those statements.

Does anyone have any ideas why I am having this issue?

For now, I would take a workaround if anyone has any. Basically what
I need is a bit flag that lets me know if this is my first access to
the page. I cannot use a viewstate boolean flag because I need it in
the Page_Init and we don't want to use the QueryString, because we
like to keep a clean URL here. Any Ideas?
 
B

bruce barker

you are abusing the ajax model. you have a very poor design, and it will
probably fail badly if used over a slower connection (say a dsl).

you should read the docs on how update panels work. but here is a short
summary:

1) a trigger control is clicked. javascript catches the event and decides to
do a async postback.
2) all form data on the page is collected and converted into a form post
string.
3) via xmlhttprequest (or an iframe) the data is posted to the server as a
standard form post, and a response handler is setup.
4) the server process the request. becuase it detects its a async postback,
only the update panel html, a scriptmanger declared javascript is passed
back to the client.
5) on the client gets the response and calls the updatepanel event handler
6) the event handler parses the response html, calls disponse on all object
in the update panel, set the innerhtml to the passed html, then loads any
javascript commands passed back.

now this all happens async. what happens if you start a second (or more)
postback before the first one completes? there is no way to the server
processing of the first request, and if there is session the server will not
process the second request until the first completes. what the client
library does, is if a second request comes before the first on completes, it
cancels the first then starts a new one.

this means if the users click several of your checkboxes during a postback,
once processed it will have to handle the case that several are changed in
one post.

you should add javascript to disable all the controls in the update panel on
postback, then display some animation/essage. the ajaxtoolkit has a control
that does this.

-- bruce (sqlwork.com)
 
S

Scott Roberts

PSY said:
I have an asp.net webpage.

On that page, there is an update panel with several check boxes in
it. Each of those check boxes has an autopostback="true" attribute
set and a method attached to it that performs some logic on the page.
When one of these events is fired, a partial postback is performed and
the code for that event and the page life cycle events fire
(Page_Init, Page_Load, etc,,,) In my Page_Init and Page_Load blocks,
there is code that should only be executed when the page is first
loaded. Hence, I performed a check for Page.IsPostBack andalso
ScriptManager.GetCurrent(Page).IsInAsyncPostBack during these phases.
Typically, if you click one of these checkboxes, the event fires and
both the IsPostBack and IsInAsyncPostBack values are true, so this
code doesn't execute (Exactly what is desired). However, if you
quickly click on a number of the checkboxes one after another,
eventually you will have your IsPostBack and IsInAsyncPostBack values
become false. I know this, because I have set breakpoints inside of
this section and have examined the values of those statements.

Does anyone have any ideas why I am having this issue?

For now, I would take a workaround if anyone has any. Basically what
I need is a bit flag that lets me know if this is my first access to
the page. I cannot use a viewstate boolean flag because I need it in
the Page_Init and we don't want to use the QueryString, because we
like to keep a clean URL here. Any Ideas?

I don't know specifically why you are having a problem, but it sounds like
it is caused by simultaneous Ajax postbacks. You might look at this link for
a way to queue simultaneous Ajax postbacks:

http://geekswithblogs.net/rashid/ar...datePanel-Simultaneous-Update---A-Remedy.aspx
 
P

PSY

Bruce, I wanted to thank you for your input. This has been very
helpful. Makes perfect sense. Changed things up a bit and things are
running great now. :)

and Scott, thanks a bunch for the queuing code. Very cool stuff. :)

you are abusing the ajax model. you have a very poor design, and it will
probably fail badly if used over a slower connection (say a dsl).

you should read the docs on how update panels work. but here is a short
summary:

1) a trigger control is clicked. javascript catches the event and decides to
do a async postback.
2) all form data on the page is collected and converted into a form post
string.
3) via xmlhttprequest (or an iframe) the data is posted to the server as a
standard form post, and a response handler is setup.
4) the server process the request. becuase it detects its a async postback,
only the update panel html, a scriptmanger declared javascript is passed
back to the client.
5) on the client gets the response and calls the updatepanel event handler
6) the event handler parses the response html, calls disponse on all object
in the update panel, set the innerhtml to the passed html, then loads any
javascript commands passed back.

now this all happens async. what happens if you start a second (or more)
postback before the first one completes? there is no way to the server
processing of the first request, and if there is session the server will not
process the second request until the first completes. what the client
library does, is if a second request comes before the first on completes, it
cancels the first then starts a new one.

this means if the users click several of your checkboxes during a postback,
once processed it will have to handle the case that several are changed in
one post.

you should add javascript to disable all the controls in the update panel on
postback, then display some animation/essage. the ajaxtoolkit has a control
that does this.

-- bruce (sqlwork.com)

Bru
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top