AJAX UpdatePanel - IsInAsyncPostBack and IsPostBack returning false
AJAX UpdatePanel - IsInAsyncPostBack and IsPostBack returning false
am 01.02.2008 16:59:45 von 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?
RE: AJAX UpdatePanel - IsInAsyncPostBack and IsPostBack returning fals
am 01.02.2008 18:02:00 von brucebarker
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)
"PSY" wrote:
> 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?
>
Re: AJAX UpdatePanel - IsInAsyncPostBack and IsPostBack returning false
am 01.02.2008 18:32:33 von Scott Roberts
"PSY" wrote in message
news:7c698d16-14a8-4977-b0c5-06e51db33f4d@m34g2000hsf.google groups.com...
>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/archive/2007/08/08/Asp.net- Ajax-UpdatePanel-Simultaneous-Update---A-Remedy.aspx