Howto inherit from an exisiting webcontrol in VS 2005

Discussion in 'ASP .Net' started by Guillaume Hanique, Sep 6, 2006.

  1. 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, Sep 6, 2006
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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, Sep 6, 2006
    #2
    1. Advertising

  3. 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" <> wrote in message
    > news:...
    >> 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, Sep 6, 2006
    #3
  4. 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" <> wrote in message
    >> news:...
    >>> 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, Sep 6, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Josema

    Inherit from webcontrol or webcontrols

    Josema, Feb 24, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    129
    Josema
    Feb 24, 2004
  2. Adnan Qamar

    Customizing exisiting DataGrid Functionality

    Adnan Qamar, Apr 28, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    115
    Rick Spiewak
    Apr 29, 2004
  3. Josema

    inherit from webcontrol or webcontrols?

    Josema, Feb 24, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    117
    Alvin Bruney [MVP]
    Mar 2, 2004
  4. Sean Warburton
    Replies:
    6
    Views:
    142
    Brian Candler
    Jan 27, 2010
  5. korssane korssane

    how to update an exisiting .PO file

    korssane korssane, Mar 15, 2011, in forum: Ruby
    Replies:
    0
    Views:
    119
    korssane korssane
    Mar 15, 2011
Loading...

Share This Page