RSS

[ASP.NET][C#] ASP page loading twice

Reason behind this post is because I would like to document all the problems I had encountered and the solution for my and all visitor's convenience in the possible future.

As the titled states; I've recently, to be exact, 2 days back, encountered this strange phenomenon whereby my asp page loads twice when I click on the button, asp:imageButton to be exact. I'm working with this search function you see. I have to pass a value from this page, back to this page. Don't get it?

Let's say, I have a webpage called report.aspx. There's a search function inside, and after the user entered a value, the user has to click on a button to pass that value for a search, right? yea, so, I stored the value using Session, as I thought it was the most convenient and efficient way to pass a value from report.aspx back to report.aspx because the page has to be posted back in order to fire off the next function.

However, as convenient as it may seemed to be, the downside of Session is that it stores in two places at the same time; the server side and the client side. Hence, the page loads twice.

Advance explanation: the first click of the button stores the Session on the Server side but not the client side. Therefore, it only updates the Server side and not the Client side. Which means, the user has to click on the button twice then only the user could view the updated page with the search result.

Solution:
Dispose the use of Session and replace it with QueryString. Problem solved.
I'll assume that everyone who are reading this knows how to work a QueryString. If you have any inquiries or need a pointer, feel free to drop me a comment and I'll get back to you. Cheers all!!

  • www.tips-fb.com
  • Follow LBenjamin on Twitter
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 peepz:

Post a Comment