codeulike
codeulike

Reputation: 23064

ASP.NET binding to a UserControl property

This should be really easy but I can't figure out how to make it work...

I have an ASP.NET UserControl (.ascx) with the following property:

public string LabelCssClass
{
    get
    {
        return _labelCssClass;
    }
    set
    {
        _labelCssClass = value;
    }
}

I want to bind that property into the HTML of the UserControl at run time, using the <%# syntax. I imagine it must be something along these lines:

<td class="<%# Eval("LabelCssClass") %>" >

I've tried all different versions of Eval() and so on ... I'm not getting errors but the binding isn't working, and my breakpoints show that the property is not being accessed.

Whats the correct syntax? cheers

Upvotes: 0

Views: 3345

Answers (2)

Nathan Taylor
Nathan Taylor

Reputation: 24606

Kevin's answer is probably closer to what you are trying to achieve; however, you can successfully use the <%# %> syntax in the standard markup if you call DataBind() on the Page itself.

Upvotes: 2

kemiller2002
kemiller2002

Reputation: 115430

I think what you might want is this:

   <td class="<%=LabelCssClass%>">

Upvotes: 3

Related Questions