tags:

views:

93

answers:

4

I'm not a beginner, but the more I think about this issue, the more I'm troubled for not finding an elegant solution.

Writing a C# .NET web site, I realized that there are several components that I need use in different pages, with more or less the same functionality, and I want to find a way to write them once and then reuse.

For example, a search box or several GridViews which I use in several pages. This "components" are built of several ASPX controls, methods, maybe some JavaScript, etc.. They are too complicated to be just duplicated and too specific to be created as controls.

What do you think should be the best approach of writing an reusing such elements. These are the solutions I've found so far, each with each own drawbacks:

  1. iframe - as a matter of fact, with all of its problems works fine for me (for the search box). I wrote one aspx/cs page with all the search behavior (it's quite complicated) - and then on each page I want this search box, I add an iframe.

  2. Master pages - this one I've found quite tricky. I've found out you could write a nested master page, but I could not figure out how could that help me. The Master page method - sets the child page as the first page (which calls its parent Master). But in my case, I have the main page which has his child components.

3.UpdatePanel - I could use UpdatePanel - and write a shared function that will populate it with the required components and code. Ok, that might work, but the code is very hard for maintenance (you need to write all the components manually with C#)

Any idea ? Did I miss anything trivial solution .

+3  A: 

An IFrame is not a solution to any component composition and reuse issue.

MasterPages are a higher level composition tool that are not related to your question.

UpdatePanels, again, are not a solution to reuse.

Compose a UserControl or brew a pot of coffee and learn to write a ServerControl.

Sky Sanders
A: 

I think the best way to do this because you have multi control inside your component building a usercontrol

about the complixty , it's ok because the time you will spend building this control will save a lot of time to write it in every page

Amgad Fahmi
A: 

Typically, UserControls do what you are describing, they have their own .ascx markup file with associated .cs codebehind file.

And of course, you can expose properties on your UserControl that you can declaratively set from its parent control, which could either be another usercontrol, or the ASP.NET page itself.

Wim Hollebrandse
A: 

As I originally commented either use ascx (user controls) or if you want to widgetize your pages, you can stick with aspx and use UFrame (jQuery) plugin.

epitka