0

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

2 Answers 2

3

I think what you might want is this:

   <td class="<%=LabelCssClass%>">
Sign up to request clarification or add additional context in comments.

3 Comments

Thats the one! Thanks. What is the name of the '<%=' type of binding, versus the '<%#' type? ... I had real trouble looking up help for this ...
It's not binding. <%= is shorthand for Response.Write().
Oh yeah : S ... I'm so used to thinking of the yellow <% things as being about binding that I forget you can also embed code ... thanks
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.