469,898 Members | 1,537 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Howto inherit from an exisiting webcontrol in VS 2005

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
Sep 6 '06 #1
3 1539
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:myClassin your ASPX page.

Hope this helps

"Guillaume Hanique" <de*********@nospam-0admicom.nlwrote in message
news:OX**************@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

Sep 6 '06 #2
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:myClassin your ASPX page.

Hope this helps

"Guillaume Hanique" <de*********@nospam-0admicom.nlwrote in message
news:OX**************@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

Sep 6 '06 #3
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
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:myClassin your ASPX page.

Hope this helps

"Guillaume Hanique" <de*********@nospam-0admicom.nlwrote in message
news:OX**************@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

Sep 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Alejandro Lapeyre | last post: by
reply views Thread by Gary Kimble via .NET 247 | last post: by
3 posts views Thread by Jill Graham | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.