Advertisement Jump to content
Sign in to follow this  

[.net] ASP.NET - Postback and events

This topic is 4104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently working with a custom made control to display some data. This control is repeated multiple times over the page(Depending on the amount of results from an SQL query). Each of these control instances have 3 tiny buttons: Edit / Delete / Lock/Unlock. When one of these buttons is clicked, I just trigger it's OnClick and pass that event on. However, I noticed that the entire page is being reloaded(ie, DB query, building up the controls and then passing on the event). Performance wise, this means that I'm query the DB an additional time for things I already know. Would it be smarter to do just call "edit.aspx?id=value" or "delete.aspx?id=value", etc.? Requires a bit of parsing, but saves the DB query and constructing the entire page. Toolmaker

Share this post

Link to post
Share on other sites
1. Use result caching.
2. Check for postback, Page.Load gets called irregardless of postback or not, that's why there's a flag you can check to see if you're dealing with a postback.

Share this post

Link to post
Share on other sites

All you need to do is put the operations that you do not want to be repeated on a postback in a if-construct like this:

// this code will only run when navigating to this page from another page

All the data that you need during a postback that is gathered during the first load of the page should be cached somewhere.
In no particular order (each with its own pros and cons)
1. request parameters: url params
2. Session object: per user, costs server memory
3. Application object: for all users, no protection
4. Viewstate: on the page, costs bandwidth

Most ASP.NET controls store their state in the viewstate by default.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!