Usercontrol +code block in between start and end tag

Discussion in 'ASP .Net' started by Chris, Dec 2, 2010.

  1. Chris

    Chris Guest

    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:
    -------------------------------------------------------------------------------------------------
    <uc:Error_Indicator runat="server">This is an error message!</
    uc:Error_Indicator>

    any relevant help or advice greatly appreciated!!
     
    Chris, Dec 2, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keithb
    Replies:
    1
    Views:
    916
    Bruce Barker
    Mar 29, 2006
  2. shruds
    Replies:
    1
    Views:
    832
    John C. Bollinger
    Jan 27, 2006
  3. Noam Raphael
    Replies:
    17
    Views:
    521
    Noam Raphael
    May 26, 2004
  4. morrell
    Replies:
    1
    Views:
    963
    roy axenov
    Oct 10, 2006
  5. TS
    Replies:
    1
    Views:
    110
    Steven Cheng[MSFT]
    Dec 19, 2007
Loading...

Share This Page