Usercontrol +code block in between start and end tag

C

Chris

Hi all,

i want to create a usercontrol that I can use in my pages in a similar
way to the Label control:

<asp:Label ID="lblUserName" runat="server"><%=User.Name%></asp:Label>

I have created a usercontrol that allows text in between the start and
end tag, which works fine, however I cannot place a code-block in
there, as I will get the following error:

Parser Error Message: Code blocks are not supported in this context.

This is the actual content in my usercontrol.ascx:
-----------------------------------------------------------------------
<asp:Image ID="imgMain" runat="server" ImageUrl="~/Images/Icons/emblem-
important.png" />

this is the actual code in my usercontrol.ascx.cs:
---------------------------------------------------------------------------
[ParseChildren(true, "InnerHTML")]
[PersistChildren(true)]
public partial class Include_UserControls_Error_Indicator :
System.Web.UI.UserControl
{
[PersistenceMode(PersistenceMode.InnerProperty)]
public string InnerHTML { get; set; }

protected void Page_Load(object sender, EventArgs e)
{
imgMain.ToolTip = InnerHTML;
}
}

and this is how I want to use the usercontrol on my page:
-----------------------------------------------------------------------------------
<uc:Error_Indicator runat="server"><%=ErrorMessage %></
uc:Error_Indicator>

I am able to use it like this, however this is not how i want to use
it:
 

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,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top