Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4336892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:52:10+00:00 2026-05-21T10:52:10+00:00

I have created a UserControl with an Inner Property called Actions, which is a

  • 0

I have created a UserControl with an Inner Property called “Actions”, which is a List of “Action” objects. The code looks like this:

[ParseChildren(true)]
public class MyLink : UserControl
{
    readonly List<Action> _actions = new List<Action>();

    [PersistenceMode(PersistenceMode.InnerProperty)]
    public List<Action> Actions
    {
        get { return _actions; }
    }

    public string Text { get;set; }
    public string Url { get;set; }
    public string MenuName { get; set; }

    protected override void Render(HtmlTextWriter writer)
    {
        //Build link
        StringBuilder sb = new StringBuilder();
        sb.Append(@"
            <table class=""myLink"">
                <tr>
                    <td class=""myLinkLeft""><a href=" + Url + @">" + Text + @"</a></td>
                    <td class=""myLinkRight " + MenuName + @"_trigger"">&nbsp;</td>
                </tr>
            </table>
        ");

        //Build actions
        sb.Append("<ul id=\"" + MenuName + "_actions\" class=\"contextMenu\">");

        foreach (Action action in _actions)
        {
            sb.Append("<li class=\"" + action.CssClass + "\"><a href=\"#" + action.Url + "\">" + action.Text + "</a></li>");
        }

        sb.Append("</ul>");

        writer.Write(sb.ToString());
    }
}

public class Action : UserControl
{
    public string Url { get; set; }
    public string Text { get; set; }
    public string ImageUrl { get; set; }
    public string CssClass { get; set; }
}

If I then put this code in my aspx inside a DataRepeater, it works fine:

<uc1:MyLink runat="server" Url="/" Text='<%#DataBinder.Eval(Container.DataItem,"Text") %>' MenuName="contextMenu" id="contextMenu">
    <Actions>
        <uc1:Action runat="server" Url="http://mysite.com" Text="MyUrl"  />
        <uc1:Action runat="server" Url="http://google.com" Text="Google" />
    </Actions>
</uc1:MyLink>

However, if I try to bind data to the attributes of the Action elements like so:

<uc1:MyLink runat="server" Url="/" Text='<%#DataBinder.Eval(Container.DataItem,"Text") %>' MenuName="contextMenu" id="contextMenu">
    <Actions>
        <uc1:Action runat="server" Url='<%#DataBinder.Eval(((RepeaterItem)Container.Parent).DataItem,"Url") %>' Text="MyUrl"  />
        <uc1:Action runat="server" Url="http://google.com" Text="Google" />
    </Actions>
</uc1:MyLink>

I merely get the actual text “<%#DataBinder.Eval(((RepeaterItem)Container.Parent).DataItem,”Url”) %>” assigned to the Url property, and not the evaluated server expression as I expected.

I’ve googled this for hours but cannot seem to find anybody else trying to do this. Any ideas why this isn’t working and how to get around it?

Thanks,
Bjoern

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:52:11+00:00Added an answer on May 21, 2026 at 10:52 am

    I ended up using tokens for the innermost databinding and then handling the replacement in my control on bind. So the ASPX code looks like this:

    <uc1:MyLink runat="server" Url="/">
       <Actions>
          <uc1:Action Url="/Page.aspx?cpr=##cpr##&opgaveId=##id##" />
          <uc1:Action Url="/Test.aspx" />
       </Actions>
    </uc1:MyLink>
    

    And the added CS code like this:

    protected override void OnInit(EventArgs e)
    {
        DataBinding += BindData;
    }
    
    public void BindData(object sender, EventArgs e)
    {
        MyLink pl = (MyLink) sender;
        IDataItemContainer container = (IDataItemContainer) pl.NamingContainer;
        foreach (Action action in _actions)
        {
            action.Url = ReplaceTokens(action.Url, container);
            action.Text = ReplaceTokens(action.Text, container);
        }
    }
    
    private static string ReplaceTokens(string text, IDataItemContainer container)
    {
        Regex re = new Regex("##.*?##", RegexOptions.Compiled | RegexOptions.Singleline);
        StringBuilder sb = new StringBuilder(text);
    
        foreach (Match m in re.Matches(text))
        {
            string tokenValue = DataBinder.GetPropertyValue(container.DataItem, m.Value.Substring(2, m.Value.Length - 4), "{0}");
            sb.Replace(m.Value, tokenValue);
        }
        return sb.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MVVM Light. I have created a window that looks like this:
I have created a UserControl called AutorControl with a method to clear its textbox:
I have a custom usercontrol created by myself which belongs to mine baseControls elements.
I have a page with a UserControl (in which linkbuttons are dynamically created). On
I have created a user control (CheckedDirTree) that exposes a CheckedFolder property which in
I have created Usercontrol called Attach_Template and I assigned its ID as attachTemplate in
I have a created a UserControl with a combobox in it. This combobox is
I have created a class that is simply THIS Class UserControlBase Inherits UserControl End
Background : I have created this UserControl. In the constructor of the user control
I have created a WPF UserControl called ChartPanel to my .NET 4.0. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.