vb.net - implementing mostly repeating content in ASP.NET WebForms' controls -


the original problem how make maintainable code given need have menu bar similar not identical in webforms.

at first glance thought wanted make placeholder in custom user control, placed in master page, access placeholder, putting in unique content within webform , happy , maintainable. after reading through forms , through trial , error, realize there problems every solution have tried:

  1. putting placeholder control in user control makes placeholder , each of contents difficult access in web form (relying on nested instances of findcontrol("id")), events difficult bubble (i assume have when control created in code behind referenced) or bind (not successful yet despite referencing: http://msdn.microsoft.com/en-us/library/t4z863dh(vs.71).aspx), , code difficult maintain if want move/rename control.
  2. nesting controls gives same problem because want use 1 control - making small modifications on many pages. if nest still have have cross-control knowledge of each other difficult in asp.net. regardless, if nested user controls need unique user control per webform right?
  3. copying , pasting code each webform while simple repetitive , error prone.
  4. apparently, shouldn't try inherit user controls make unique children: how (if @ all) can make asp.net usercontrol inherit usercontrol?.

i'm new asp.net. there general strategy should use make maintainable code in scenario?

you need use master page, , put menu in there...

http://msdn.microsoft.com/en-us/library/wtxbf3hh(v=vs.100).aspx

then, data-driven menu, try use 1 of template controls repeater bind data.

for example, have query returns page name , link - bind repeater control produce menu.

<asp:repeater runat="server">     <headertemplate><ul></headertemplate>     <itemtemplate><li><a href='<% eval("link") %>'><%# eval("pagename") %></a></li></itemtemplate>     <footertemplate></ul></footertemplate> </asp:repeater> 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -