Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Howto inherit from an exisiting webcontrol in VS 2005 (http://www.velocityreviews.com/forums/t368864-howto-inherit-from-an-exisiting-webcontrol-in-vs-2005-a.html)

Guillaume Hanique 09-06-2006 09:57 AM

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

Van den Driessche Willy 09-06-2006 10:55 AM

Re: Howto inherit from an exisiting webcontrol in VS 2005
 
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




Guillaume Hanique 09-06-2006 11:12 AM

Re: Howto inherit from an exisiting webcontrol in VS 2005
 
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

>
>


Guillaume Hanique 09-06-2006 11:36 AM

Re: Howto inherit from an exisiting webcontrol in VS 2005
 
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: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

>>
>>



All times are GMT. The time now is 07:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.