Jump to content


Photo

Inner Content Of Custom Controls


  • Please log in to reply
1 reply to this topic

#1 mark.norgate

mark.norgate

    New Member

  • Members
  • Pip
  • 7 posts

Posted 16 March 2009 - 11:09 AM

Hello

I want to create a custom control that is essentially a hyperlink with various additional attributes.

Just a simplified example:

<cc1:MySpecialHyperlink href="~login.aspx">Click here!</cc1:MySpeicalHyperlink>

I'd like to know how to get hold of the inner text node of the control programatically from within my RenderContents method (in the example above, the 'Click here!' string).

How's this done?

Mark

#2 Dan_Maharry

Dan_Maharry

    Active Member

  • O'Reilly Author
  • PipPip
  • 23 posts
  • Gender:Male
  • Location:UK

Posted 22 March 2009 - 07:55 AM

QUOTE (mark.norgate @ Mar 16 2009, 07:09 PM) <{POST_SNAPBACK}>
Hello

I want to create a custom control that is essentially a hyperlink with various additional attributes.

Just a simplified example:

<cc1:MySpecialHyperlink href="~login.aspx">Click here!</cc1:MySpeicalHyperlink>

I'd like to know how to get hold of the inner text node of the control programatically from within my RenderContents method (in the example above, the 'Click here!' string).

How's this done?

Mark



Hi Mark,

Typically, if you're deriving your custom hyperlink from the standard hyperlink class, then the inner text node is set \ retrieved by the Text property. More generally, you can access it through the DefaultProperty for your control (which is typically 'Text'). Have a look at the code on page 778 for a commentary but this might work.

namespace MyControls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:MySpecialHyperlink runat=server></{0}:MySpecialHyperlink>")]
public class MySpecialHyperlink : Hyperlink
{
etc ...
Dan Maharry
Author, Programming ASP.NET 3.5
(home : blog : tumblr)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users