inherits HtmlControl

Discussion in 'ASP .Net' started by =?Utf-8?B?emlubw==?=, Jun 30, 2006.

  1. my asp.net page need to display links (<a></a>) as tabs.

    I create a class that inherits from HtmlAnchor as:


    Public Class Tab
    Inherits System.Web.UI.HtmlControls.HtmlAnchor
    '(inheriting from HtmlControl is good or bad ????)

    Private _Id As String = "myId"
    Private _innerHtml As String = "sometext"
    Private _href As String = "page.aspx"
    Private _target As String = "mytarget"

    Public Sub New()
    End Sub

    Public Overrides Property Id() As String
    Get
    Return _Id
    End Get
    Set(ByVal value As String)
    _id=value
    End Set
    End Property

    public property ... .. ... ....
    'the same as above for the rest of methods
    ...... .. . . .. . ..
    ..... .. ..
    ...
    End Class



    I want to embed the HtmAnchor control within the aspx page (myDiv is <div
    id='myDiv' runat=server></div>:
    in the code behind I have:
    ..... .. . . . ....
    Dim a As New Tab
    a.HRef = _tab.HREF
    a.ID = _tab.Id
    a.Target = _tab.Target
    a.InnerHtml = _tab.InnerHTML

    myDiv.Controls.Add(DirectCast(a, HtmlAnchor))


    but the anchor control never rendered on the page.

    obviously I'm doing something wrong, what is it?
    =?Utf-8?B?emlubw==?=, Jun 30, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?emlubw==?=

    Spartaco Guest

    > '(inheriting from HtmlControl is good or bad ????)

    htmlcontrols are not supposed to be overridden, usually there is no need, if
    you want something different just create your webcontrol.
    Spartaco, Jul 2, 2006
    #2
    1. Advertising

  3. Hi zino,

    I agree with Spartaco, for such scenario, we would recommend you create a
    custom ASP.NET webserver control rather than html server control because
    HTML server controls is not designed for further customizing and is purely
    for integrated with inline html code(with runat=server mark).

    Also, for creating a custom ASP.NET webserver control, I suggest you
    consider creating a composite control. Composite control is a server
    control which consists of other sub server controls. Therefore, you can
    add the HtmlAnchor as a child control in yoru custom composite control ,
    and also add some additional features(other propety or nested controls).
    This also maps to the "Aggregation" reuse pattern in OO(in contrast to
    inheritance reuse).

    In addition, as for developing custom composite control, the core is the
    "CreateChildControls" function where we should put the most control
    constructing code logic. Here is the msdn reference on creating a sample
    composite control:

    #Composite Server Control Sample
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcompositecontrolsa
    mple.asp?frame=true

    Hope this helps you some.

    Regards,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Jul 3, 2006
    #3
  4. Hi Zino,

    How are you doing on this issue? Have you got any progress or does our
    suggestion help you a little? If there is still anything we can help,
    please feel free to post here.

    Regards,

    Steven Cheng
    Microsoft MSDN Online Support Lead


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Jul 5, 2006
    #4
  5. Hi Steven,
    thank you for your feedback, I took your advise and discard the idea of
    inheriting from an HtmlControl, and I'm working on the composite control.



    "Steven Cheng[MSFT]" wrote:

    > Hi Zino,
    >
    > How are you doing on this issue? Have you got any progress or does our
    > suggestion help you a little? If there is still anything we can help,
    > please feel free to post here.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft MSDN Online Support Lead
    >
    >
    > ==================================================
    >
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    >
    > ==================================================
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    =?Utf-8?B?emlubw==?=, Jul 5, 2006
    #5
  6. Thanks for the followup Zino,

    Glad that the suggestion has helped you some. If you meet any further
    problem or need any other help on this, please feel free to post here.

    Regards,

    Steven Cheng
    Microsoft MSDN Online Support Lead


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Jul 6, 2006
    #6
    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. Paul
    Replies:
    1
    Views:
    3,194
    bruce barker
    Aug 4, 2003
  2. =?Utf-8?B?VmljdG9y?=

    WebControl vs. HtmlControl

    =?Utf-8?B?VmljdG9y?=, Mar 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    455
    =?Utf-8?B?VHUtVGhhY2g=?=
    Mar 3, 2004
  3. Tim Mulholland

    Make HtmlControl invisible

    Tim Mulholland, Aug 10, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    6,275
    Tim Mulholland
    Aug 13, 2004
  4. Alex Nitulescu
    Replies:
    0
    Views:
    343
    Alex Nitulescu
    Feb 22, 2005
  5. ton
    Replies:
    1
    Views:
    1,005
    Teemu Keiski
    Jun 24, 2007
Loading...

Share This Page