|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Howto inherit from an exisiting webcontrol in VS 2005I feel very stupid. I simply want to derive a control from system.web.ui.webcontrols.button and use that on my webform, but I just can't get it done. Can anyone tell me how to do that? I can create my own usercontrol (Menu: Website > Add new item... > Web User Control). This creates an aspx and an aspx.vb file in the root folder, which inherits nicely from system.web.ui.usercontrol. But I want to inherit system.web.ui.webcontrols.button. I can't change anything in this aspx and aspx.vb file to make it inherit from the button and make it work. The examples I found on the internet simply create a class and derive it from the webcontrol. But no one says if the save it in the root folder or in the App_Code folder. They use the <@ register tag to register it and they fill the assembly and namespace attributes. I tried a lot, but can't find anything I can put in the assembly and namespace attributes that makes it work. What steps do I take in VS 2005 to add a control that is derived from system.web.ui.webcontrols.button to the solution and use it in my only webform Default.aspx? Thanks so much! Guillaume Hanique You just create a class (vb sample)
class myClass inherits system.web.ui.webcontrols.button end class AFAIK you can put this class in the app_code folder. A "better" idea is to create a webcontrol library (a DLL) and put the new control in there. In you website project you put a reference to this webcontrol library (this will copy it to the bin directory an VS2005 will make sure changes propagate upon build) To use it in your page, you can either use the @register directive in the aspx markup, or register you control once and for all in the web.config of your web application. <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.web> <controls> <add assembly="YourAssemblyName" namespace="yourNameSpace" tagPrefix="XYZ" /> </controls> </system.web> </configuration> afterwards you use <XYZ:myClass> in your ASPX page. Hope this helps Show quoteHide quote "Guillaume Hanique" <development@nospam-0admicom.nl> wrote in message news:OXs7GtZ0GHA.4796@TK2MSFTNGP06.phx.gbl... > Hi, > > I feel very stupid. I simply want to derive a control from > system.web.ui.webcontrols.button and use that on my webform, but I just > can't get it done. Can anyone tell me how to do that? > > I can create my own usercontrol (Menu: Website > Add new item... > Web > User Control). This creates an aspx and an aspx.vb file in the root > folder, which inherits nicely from system.web.ui.usercontrol. But I want > to inherit system.web.ui.webcontrols.button. I can't change anything in > this aspx and aspx.vb file to make it inherit from the button and make > it work. > > The examples I found on the internet simply create a class and derive it > from the webcontrol. But no one says if the save it in the root folder > or in the App_Code folder. They use the <@ register tag to register it > and they fill the assembly and namespace attributes. I tried a lot, but > can't find anything I can put in the assembly and namespace attributes > that makes it work. > > What steps do I take in VS 2005 to add a control that is derived from > system.web.ui.webcontrols.button to the solution and use it in my only > webform Default.aspx? > > Thanks so much! > > Guillaume Hanique Thanks for your prompt reply.
I did create a class like that and tried to put it in de App_Code folder. The problem is I do not know how to use the @Register directive (which I prefer) or how to add it in web.config. What is my assembly name and what is my namespace, or how do determine it? I named my project ppcinstall, but <%@ Register TagPrefix="XYZ" Assembly="ppcinstall" Namespace="ppcinstall" %> gives the compile error that it cannot find the assembly ppcinstall. My Projects directory (C:\Inetpub\wwwroot\ppcinstall) does not have a dll anywhere, only vb-files, aspx-files, a web.config file, an App_Data folder and an App_Code folder. Of course I could create a webcontrol library, but why not have it simply in my webproject? If you could help me further, I would very much appreciate it. Thanks, Guillaume Hanique Show quoteHide quote > You just create a class (vb sample) > > class myClass > inherits system.web.ui.webcontrols.button > end class > > AFAIK you can put this class in the app_code folder. A "better" idea is to > create a webcontrol library (a DLL) and put the new control in there. In > you website project you put a reference to this webcontrol library (this > will copy it to the bin directory an VS2005 will make sure changes propagate > upon build) > > To use it in your page, you can either use the @register directive in the > aspx markup, or register you control once and for all in the web.config of > your web application. > > > <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> > <system.web> > <controls> > <add > assembly="YourAssemblyName" namespace="yourNameSpace" > tagPrefix="XYZ" /> > </controls> > </system.web> > </configuration> > > afterwards you use > <XYZ:myClass> in your ASPX page. > > Hope this helps > > "Guillaume Hanique" <development@nospam-0admicom.nl> wrote in message > news:OXs7GtZ0GHA.4796@TK2MSFTNGP06.phx.gbl... >> Hi, >> >> I feel very stupid. I simply want to derive a control from >> system.web.ui.webcontrols.button and use that on my webform, but I just >> can't get it done. Can anyone tell me how to do that? >> >> I can create my own usercontrol (Menu: Website > Add new item... > Web >> User Control). This creates an aspx and an aspx.vb file in the root >> folder, which inherits nicely from system.web.ui.usercontrol. But I want >> to inherit system.web.ui.webcontrols.button. I can't change anything in >> this aspx and aspx.vb file to make it inherit from the button and make >> it work. >> >> The examples I found on the internet simply create a class and derive it >> from the webcontrol. But no one says if the save it in the root folder >> or in the App_Code folder. They use the <@ register tag to register it >> and they fill the assembly and namespace attributes. I tried a lot, but >> can't find anything I can put in the assembly and namespace attributes >> that makes it work. >> >> What steps do I take in VS 2005 to add a control that is derived from >> system.web.ui.webcontrols.button to the solution and use it in my only >> webform Default.aspx? >> >> Thanks so much! >> >> Guillaume Hanique > > Solved it.
- The file has to be stored in the App_Code folder. - The class has to be in a namespace. - In the register directive omit the assemblyname. App_Code\MyButton.vb: Namespace MyControls Public Class MyButton Inherits System.Web.UI.WebControls.Button End Class End Namespace The register-directive will be: <%@ Register TagPrefix="xyz" Namespace="MyControls" %> The control can be used with: <xyz:MyButton id="btnMine" runat="server" text="MyButton" /> Thank you for your help! Your instructions helped me to pinpoint my mistake. Guillaume Hanique Show quoteHide quote > Thanks for your prompt reply. > > I did create a class like that and tried to put it in de App_Code > folder. The problem is I do not know how to use the @Register directive > (which I prefer) or how to add it in web.config. > > What is my assembly name and what is my namespace, or how do determine it? > > I named my project ppcinstall, but > <%@ Register TagPrefix="XYZ" Assembly="ppcinstall" > Namespace="ppcinstall" %> > gives the compile error that it cannot find the assembly ppcinstall. > > My Projects directory (C:\Inetpub\wwwroot\ppcinstall) does not have a > dll anywhere, only vb-files, aspx-files, a web.config file, an App_Data > folder and an App_Code folder. > > Of course I could create a webcontrol library, but why not have it > simply in my webproject? > > If you could help me further, I would very much appreciate it. > > Thanks, > Guillaume Hanique > >> You just create a class (vb sample) >> >> class myClass >> inherits system.web.ui.webcontrols.button >> end class >> >> AFAIK you can put this class in the app_code folder. A "better" idea >> is to >> create a webcontrol library (a DLL) and put the new control in there. In >> you website project you put a reference to this webcontrol library (this >> will copy it to the bin directory an VS2005 will make sure changes >> propagate >> upon build) >> >> To use it in your page, you can either use the @register directive in the >> aspx markup, or register you control once and for all in the >> web.config of >> your web application. >> >> >> <configuration >> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> >> <system.web> >> <controls> >> <add >> assembly="YourAssemblyName" namespace="yourNameSpace" >> tagPrefix="XYZ" /> >> </controls> >> </system.web> >> </configuration> >> >> afterwards you use >> <XYZ:myClass> in your ASPX page. >> >> Hope this helps >> >> "Guillaume Hanique" <development@nospam-0admicom.nl> wrote in message >> news:OXs7GtZ0GHA.4796@TK2MSFTNGP06.phx.gbl... >>> Hi, >>> >>> I feel very stupid. I simply want to derive a control from >>> system.web.ui.webcontrols.button and use that on my webform, but I just >>> can't get it done. Can anyone tell me how to do that? >>> >>> I can create my own usercontrol (Menu: Website > Add new item... > Web >>> User Control). This creates an aspx and an aspx.vb file in the root >>> folder, which inherits nicely from system.web.ui.usercontrol. But I want >>> to inherit system.web.ui.webcontrols.button. I can't change anything in >>> this aspx and aspx.vb file to make it inherit from the button and make >>> it work. >>> >>> The examples I found on the internet simply create a class and derive it >>> from the webcontrol. But no one says if the save it in the root folder >>> or in the App_Code folder. They use the <@ register tag to register it >>> and they fill the assembly and namespace attributes. I tried a lot, but >>> can't find anything I can put in the assembly and namespace attributes >>> that makes it work. >>> >>> What steps do I take in VS 2005 to add a control that is derived from >>> system.web.ui.webcontrols.button to the solution and use it in my only >>> webform Default.aspx? >>> >>> Thanks so much! >>> >>> Guillaume Hanique >> >>
Other interesting topics
OleDbDataAdapter created in code behaves differently from one created by wizard.
Intellisense with web.config registration of controls Q about ASP speeds XML PROBLEM HELP NEEDED URGENTLY problem with GridView Iframe extra space Error BC30451 Making New web site by using ASP.Net 2005 change the scrollbar color in a listbox date in datagrid |
|||||||||||||||||||||||