In the following example
<uc1:MyUserControl> <p>this is html</p> </uc1:MyUserControl>
How can I access "<p>this is html</p>" as a string in MyUserControl so that I can insert it into the response?
I'm not talking about passing a string parameter like <uc1:MyUserControl myparameter="<p>this is html</p>" /> , but how can I access the genuine multi-layer intellisensed HTML markup or between the opening and closing tags, or some other mechanism, such as the <MessageTemplate> .
Reward points for a solution that works in ASP.NET MVC 3!
EDIT:
Thanks to StriplingWarrior and this link , the magic was done as the missing piece of the puzzle:
So, in any view:
<%@ Register src="../../Shared/Ribbon.ascx" tagname="Ribbon" tagprefix="uc1" %> ... <uc1:Ribbon ID="Ribbon" runat="server"> <Content> Hello world! I am <b>pure html</b> being passed into a UserControl! </Content> </uc1:Ribbon>
In Ribbon.ascx:
<%@ Control Language="C#" CodeBehind="Ribbon.ascx.cs" Inherits="NunYourBeezwax.Views.Shared.Ribbon" %> <table> <tr> <td>I am reusable stuff that wraps around dynamic content</td> <td><%= this.Content %></td> <td>And I am stuff too</td> </tr> </table>
And finally, in Ribbon.ascx.cs (must be added manually in MVC)
using System.Web.Mvc; using System.Web.UI; namespace NunYourBeezwax.Views.Shared { [ParseChildren(true, "Content")] public class Ribbon : ViewUserControl { [PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)] public string Content { get; set; } } }
Will display as:
<table> <tr> <td>I am reusable stuff that wraps around dynamic content</td> <td>Hello world! I am <p>pure html<p> being passed into a UserControl!</td> <td>And I am stuff too</td> </tr> </table>
source share