Postback confusion re: redirects

D

darrel

I'm rather confused as to what is a postback and what is not.

I have a page with a asp:dropdownlist and asp:button

There's an event on the button click that response.redirects to the same
page with an updated querystring (based on the value of the dropdownlist
selected item).

On pageload, there's a subroutine that checks for the ifPostBack

I can only get code to run within the If IsPostBack ELSE portion. Nothing
ever runs in the ifPostBack, making me assume there there isn't an actual
postback happening.

To further add confusion, if I remove the ifPostBack statement, the code
that was within the ELSE is now by itself in the pageLoad and does not
execute. In otherwords, for the pageLoad content to work, I have to wrap it
in a If IsPostBack ELSE.

I'm not comprehending some .net logic here. ;o)

-Darrel
 
M

Marina

This is what's happening:

user clicks button
page postbacks
page_load runs
ispostback = true -> this code runs
button click handler runs
button click handler redirects to the same page
page_load runs
ispostback = false
 
D

darrel

This is what's happening:
user clicks button
page postbacks
page_load runs
ispostback = true -> this code runs
button click handler runs
button click handler redirects to the same page
page_load runs
ispostback = false

Aha! THANK YOU! that makes sense now. Button handler runs AFTER the
postback.

Ok. Hmm...so, I can put the redirect in the postback.

So, the follow up question:

This doesn't seem very efficient. I'm hitting the page twice for each push
of the button. Is there a way to streamline this? One option is to not use
the response.redirect and just have the page update on the postback.
However, I want to use a response.redirect so that I can change the URL
(adding/updating a querystring) so that the page is bookmarkable. Is there a
way to manipulate the URL on the postback rather than having to do a
redirect? Or is this double-page-load not really that big of an issue?

-Darrel
 
M

Marina

As far as I know, there is no way to alter the query string manually - this
is read only.

The answer in this case is, no, there is no other way to do it on the
server.

The only suggestion would be to have client side javascript run when the
button is clicked, that redirects to the same page with the appropriate
querystring. That way, you only go to the server once. Of course, if your
click handler is doing other things, like updating a database, etc, you
would not be able to use this.
 
D

darrel

The answer in this case is, no, there is no other way to do it on the

With that said, should I be too worried about this being inefficient?

From what I can tell, the page is processed twice on the server, but only
sent once to the user. I may be wrong on that, but if it's true, then I'm
not that worried from the end-user experience standpoint.
The only suggestion would be to have client side javascript run when the
button is clicked, that redirects to the same page with the appropriate
querystring.

For accessibility reasons, we're trying to avoid all javascript for critical
things like navigation.

It seems that this is a limited, but real limitation to the whole .net
post-back concept.

Hmm...

-Darrel
 
M

Marina

Well, this limitation is no different then using ASP or anything else.
There is no way around it, but if you are posting to a page (same or
different), and then doing a redirect, you will always hit the server twice.

Javascript is something often used to elminate this sort of behavior, but if
you don't want to use it, you are stuck with the server type of behavior.
 
D

darrel

Well, this limitation is no different then using ASP or anything else.
There is no way around it, but if you are posting to a page (same or
different), and then doing a redirect, you will always hit the server
twice.

Does the page get sent twice? I guess I wouldn't be two concerned about the
double-hit on the server, but I certainly don't want the end-user having to
double load the page.
Javascript is something often used to elminate this sort of behavior, but if
you don't want to use it, you are stuck with the server type of behavior.

Well, if this is trully a hit on the server (granted, this isn't a huge
fortune 500 site or anything), then I suppose I could just implement a
javascript behavior for those that have it, and resort to the server for
those that don't.

-Darrel
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top