By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,909 Members | 1,996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,909 IT Pros & Developers. It's quick & easy.

web control to many pages

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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/de...classtopic.asp

HTH
----------------
Dave Fancher
http://davefancher.blogspot.com
Nov 19 '05 #2

P: n/a
For now, unless your web site is huge, it's easiest to just drag a control
onto each page.
Another approach would be to use an HTTPHandler to inject one into the
output stream.

Here's more info:
http://SteveOrr.net/faq/UserCustom.aspx
http://msdn.microsoft.com/library/de...ebControls.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Just D." <no@spam.please> wrote in message
news:BRYde.989$eU.451@fed1read07...
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.

Nov 19 '05 #3

P: n/a
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.

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
For now, unless your web site is huge, it's easiest to just drag a control
onto each page.
Another approach would be to use an HTTPHandler to inject one into the
output stream.

Here's more info:
http://SteveOrr.net/faq/UserCustom.aspx
http://msdn.microsoft.com/library/de...ebControls.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Just D." <no@spam.please> wrote in message
news:BRYde.989$eU.451@fed1read07...
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.


Nov 19 '05 #4

P: n/a
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...mtemplates.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/20...asterPages.asp

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

"Just D." <no@spam.please> wrote in message
news:TL%de.1009$eU.570@fed1read07...
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.

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
For now, unless your web site is huge, it's easiest to just drag a
control onto each page.
Another approach would be to use an HTTPHandler to inject one into the
output stream.

Here's more info:
http://SteveOrr.net/faq/UserCustom.aspx
http://msdn.microsoft.com/library/de...ebControls.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Just D." <no@spam.please> wrote in message
news:BRYde.989$eU.451@fed1read07...
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.



Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.