Monday, March 26, 2012

web control to many pages

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...lclasstopic.asp

HTH
------
Dave Fancher
http://davefancher.blogspot.com
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/d...WebControls.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.
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]" <Steve@.Orr.net> wrote in message
news:%23TeF36GUFHA.1040@.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/d...WebControls.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.
>>
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/writin...emtemplates.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/2...MasterPages.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]" <Steve@.Orr.net> wrote in message
> news:%23TeF36GUFHA.1040@.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/d...WebControls.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.
>>>
>>
>>

0 comments:

Post a Comment