inherits HtmlControl

G

Guest

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?
 
S

Spartaco

'(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.
 
S

Steven Cheng[MSFT]

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.)
 
S

Steven Cheng[MSFT]

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.)
 
G

Guest

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.
 
S

Steven Cheng[MSFT]

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top