Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Currently I'm working a bit with ASP.NET and trying to find the best way to navigate through pages. Right now I have an UpdatePanel which has a Placeholder inside it. This Placeholder will then add the usercontrol I need.

I've been looking around on the internet and some say that this is a really bad thing to do, while others use it without trouble. Is this whole UserControl inside Placeholder inside updatepanel good/bad?

While I've been trying to implement this I run into a problem with postback. When I click a button on my "Main page" to add a new UserControl to the Placeholder, the Page. IsPostback is of course the same on the UserControl and therefore it will always be true here.

Am I doing something wrong or do I need to use a session variable to keep my UserControlPostback perhaps?

I'm open to all options, just need to find the preferred way.

share|improve this question
2  
Maybe you could take a step back and tell us why you want to do such a thing. It might help to find a better solution. –  patmortech Jan 13 '12 at 12:14
    
Hi. Well im more or less just trying to find the best way to navigate through pages without having to do full postbacks all the time. This i tried to solve by having the updatepanel with a placeholder which contains usercontrols. This makes no sense perhaps? –  Thomas Jan 13 '12 at 12:54
    
What is inside your Usercontrols -- do they have buttons and form fields? Or is this all about loading different sets of static content without leaving the current page? –  patmortech Jan 13 '12 at 17:41
add comment

1 Answer

I think you need to take a step back and say "Are UpdatePanels the spawn of Satan?".

But seriously, the way you're outlining does have some fairly bad side-effects (although it's a possible strategy to go about working with dynamic content in ASP.net WebForms and I have taken a similar approach myself).

The first side-effect you'll have is that dynamically added content does not persist after a postback, so you'll have to re-add your UserControl to the Placeholder at Page_Init if you want to handle any posted form data. This can cause issues if you've got no way of telling which UserControl you added to the placeholder, but I've implemented such a solution before without this being too much of problem.

The second side-effect is the huge amount of ViewState you're going to collect as your UpdatePanels go about their business. ViewState is fairly evil, and when you're posting it to and from the server with every request, combined with it being very large, it can provide some severe speed issues from a user-perspective. I'd suggest if you do want to go down this route you should try to disable ViewState for any controls you do not expect to retrieve data from at a later date.

The other issue I can think of off the top of my head is the replication of page state. When you get a defect report from a tester (or user), with the dynamic UpdatePanel approach you will have to log a number of steps to replicate the state the system is at. If you approach from a URL-driven page load perspective, where each URL (with query string data) represents a page state the amount of time you'll need to take to track down an issue will be (hopefully) cut down to the amount of time it takes you to copy a URL and paste it into your browser navigation bar. I personally think this is the most compelling argument for trying to avoid a stateful approach web events whenever possible.

In my opinion you'd be best off optimising your page load times to avoid the issue of doing full postbacks taking too long, then looking at using AJAX functionality and JavaScript templating to handle client-side requests. Sure, it's a lot closer to the metal so you'll have to write more code, but abstractions like UpdatePanels often have only a few use cases where they're beneficial, with the UpdatePanel's particular use case being "Get it out the door fast, don't make it fast".

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.