web control to many pages

  • Thread starter Thread starter Just D.
  • Start date Start date
J

Just D.

Does anybody know an official way to setup one control on many pages, for
example menu? Since we're not having a visual inheritance yet it's not very
easy. One of the possible ways as I see is to copy the html code of this
control manually to all aspx pages and then use some call probably to a base
class method on onload to initialize and fill this control. I see that crazy
because if we need to correct something then we need to correct all pages,
but that's brainless.

How can we insert the html code of this control to all our pages on runtime?
I know that we can insert a JAVA script using RegisterClientScriptBlock, but
what about pure HTML?

Thanks,
Just D.
 
Convert the control to a UserControl and have all of your pages derive from
a custom class derived from System.Web.UI.Page (like MyAppPage : Page).
Then, in MyAppPage.Page_Load or MyAppPage.Page_Init add the control to the
page's Controls collection.

Depending on how you code the control (directly rendering HTML with the
Render() method or if the HTML is contained in an .ascx file) you can either
call it as Page.Controls.Add(new MyMenu()); or
Page.Controls.Add(Page.LoadControl("MyMenu.ascx"));

http://msdn.microsoft.com/library/d...rfsystemwindowsformsusercontrolclasstopic.asp

HTH
 
Thanks Steve,

I think that's what I wanted. I can't say that it's huge, only 130 pages
including some menu related and secondary pages... The application is
expecting to be really huge, that's true, and this approach will help to
solve this problem. Right now I'm having this control on about 60 pages, it
was easy to add it to macro and insert to all ASPX pages, but it's not
convenient for sure.

Thanks,
Just D.
 
You can create a Visual Studio template using the information in the
following link, although it's not nearly as easy as it should be.
Here are the details:
http://www.sellsbrothers.com/writing/default.aspx?content=projectitemtemplates.htm

In Visual Studio 2005 creating templates will be much easier. There will
also be Master Pages that will allow all your pages to inherit a common
structure.
http://www.c-sharpcorner.com/Code/2004/May/MasterPages.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top