O'Reilly Forums: Inner Content Of Custom Controls - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Inner Content Of Custom Controls <cc1:MyControl>How do I get this content?</cc1:MyControl>

#1 User is offline   mark.norgate 

  • New Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 07-March 09

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
0

#2 User is offline   Dan_Maharry 

  • Active Member
  • PipPip
  • Group: O'Reilly Author
  • Posts: 23
  • Joined: 17-September 08
  • 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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users