Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 28, 2008 05:15 AM by InterfaceMirror
Aug 26, 2008 02:23 PM|LINK
On the first page, I have a search form. I am trying to save all of the user's search parameters to the session, and I am displaying the user's search results on the second page using a control that pulls the values from the session. (I wanted the form
and the results to be on two different pages for "look and feel" purposes associated with my website)
The problem that I am having is that the first page isn't actually saving the values to the session. I have enabled sessions in my web config file, and I actually have this working fine on another page using different search parameters, but I can't figure
out what I am doing wrong here. Below is my "code behind" c# code. Anyone have any ideas as to what I am missing here? Thanks for your help!
Aug 26, 2008 03:50 PM|LINK
Change the redirect stmt. as like below
Aug 26, 2008 03:56 PM|LINK
Sometimes when you are setting a session before a redirection session values will be lost. The solution will be to end the response directly when using response.redirect
Hope this helps
Aug 26, 2008 04:26 PM|LINK
That is a good idea... unfortunately it didn't fix my problem. Maybe I have done something else wrong. I will go back and look at my aspx page code... or maybe the sql statement I am using on the results page is wrong. Thank you for your help!
Aug 26, 2008 05:42 PM|LINK
I double checked my sql and also the aspx search page, but everything is right. Any other ideas?
Aug 27, 2008 12:43 PM|LINK
First try to narrow down your problem.
Tell us: Are the keys stored in Session or you have session keys with empty values? I mean when you debug the code, can you step in FOR LOOP? If you are not able to step in, means session keys are not stored. And if then try to debug TextBoxes values, Are they
empty or they have values.
If they have values it means session is being lost in the Redirection. In that case Try Server.Transfer() instead of the Redirect().
Please let us know about the above questions.
Waiting to hear from you.
Aug 27, 2008 02:24 PM|LINK
Thanks so much for your help. I first tried stepping through like you said and I found that it was being lost in the redirect. Then, I saw that in the aspx page, I had indicated a post back url for the button. I removed that, and everything is working
fine now! I don't know why that should mess things up, since I used the right url in the post back url, but it works fine when that was removed. Thanks again!
Aug 28, 2008 05:15 AM|LINK
The reason is very simple. When you set PostBackUrl of the button, it means that you want to use Cross-page postback. The mechanism used by ASP.NET to corss-page postback is Client Transfer not Server transfer.
Let me clear myself with following scenario:
Let say, you don't set PostbackUrl of the button and at the same time you are performing some operation in the Button_Click event. The event cycle would be like:
This is because by default Button control posts back the page to the same container page.
Now for the second test you set PostbackUrl of the control, the event cycle is like:
The reason behind this PostBackUrl works on Client side, not on the server side. (it is completely different from Server.Transfer).
For the reference you can see
CROSS PAGE-POSTING IN ASP.NET WEB PAGES