Jump to content
  • Advertisement
Sign in to follow this  
Toolmaker

[.net] ASP.NET - Postback and events

This topic is 3918 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
Advertisement
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
Hi!

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:

if(!this.IsPostback)
{
// 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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!