AJAX and IsPostBack


B

BM

I have a question that seems like it should have a simple answer, but
I can't seem to find it by searching...

Anyway, I'm trying to capture the IsPostBack event when I select an
item within an UpdatePanel. I don't want items running during
postback (list, grid population, etc) events - pretty standard: If
IsPostBack Then Exit Sub

But, since AJAX doesn't technically postback (?), the IsPostBack is
coming back false...

So, how can I capture the Async postback done by AJAX? Is there any
IsAsyncPostBack keyword and what library is it in?

Page load process:
1. Load drop down menus
2. Load data grids

"Postback process"
1. Select datagrid row
2. Populate several fields below with further information

When I select the datagrid row, IsPostBack remains false. I've tried
splitting into multiple update panels but now they are all in a
singular panel.

TIA for the help!
 
Ad

Advertisements

B

bruce barker

an update panel async callback does set IsPostback true (as this is a just a
test for __Viewstate and the callback sends all form fields). you can also
check the scriptmanger.IsInAsyncPostBack

-- bruce (sqlwork.com)
 
B

BM

AJAX call runs as a POST back. Just test it...

Thanks - I did test it and I suppose I wasn't 100% clear. It _does_
run a PostBack but it runs through the page initialization once first
with IsPostBack=False and then it runs it again with IsPostBack=True

Page_Init() [originally under PreRender]
1 If IsPostBack Then
2 Exit Sub
3 End If
4
5 loadDropDowns()
6 loadIncompleteGrid()

Obviously when I first load the page, lines 5 and 6 run.
When I click on the DataGrid, it runs lines 5 and 6 and then runs
through again with the break at line 2

Maybe then there's something more wrong with my pages...
 
M

Mark Fitzpatrick

You may want to play with the timing. Try moving your calls to the
subroutines into an event that's further up the heirarchy such as the OnLoad
event. You should find that the behavior changes at some point as you get
further into the page lifecycle.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

BM said:
AJAX call runs as a POST back. Just test it...

Thanks - I did test it and I suppose I wasn't 100% clear. It _does_
run a PostBack but it runs through the page initialization once first
with IsPostBack=False and then it runs it again with IsPostBack=True

Page_Init() [originally under PreRender]
1 If IsPostBack Then
2 Exit Sub
3 End If
4
5 loadDropDowns()
6 loadIncompleteGrid()

Obviously when I first load the page, lines 5 and 6 run.
When I click on the DataGrid, it runs lines 5 and 6 and then runs
through again with the break at line 2

Maybe then there's something more wrong with my pages...
 
Ad

Advertisements

B

BM

You may want to play with the timing. Try moving your calls to the
subroutines into an event that's further up the heirarchy such as the OnLoad
event. You should find that the behavior changes at some point as you get
further into the page lifecycle.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression


Thanks - I did test it and I suppose I wasn't 100% clear. It _does_
run a PostBack but it runs through the page initialization once first
with IsPostBack=False and then it runs it again with IsPostBack=True
Page_Init() [originally under PreRender]
1 If IsPostBack Then
2 Exit Sub
3 End If
4
5 loadDropDowns()
6 loadIncompleteGrid()
Obviously when I first load the page, lines 5 and 6 run.
When I click on the DataGrid, it runs lines 5 and 6 and then runs
through again with the break at line 2
Maybe then there's something more wrong with my pages...

I've somewhat solved the problem just by setting the ScriptManager's
"LoadScriptsBeforeUI" property to False. It now registers a Postback
as such the first time around. Now it just calls my functions 2 or 3
times, so I'm at another issue. My pages have stopped throwing errors
at least for now.
 
Ad

Advertisements


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

Top