2

I need to set a property value of a user control from the markup.

I need to set the property called "ItemIndex" in my user control from the markup.

for some unfortunate reason, "<%: x %>" part of ItemIndex="<%: x %>" doesn't get resolved.

Basically the value of ItemIndex becomes "<%: x %>" rather than becoming the actual value of x.

Below is the code (please note the comments in CAPS).

<%@ Register TagPrefix="DDLControls" TagName="MainMenuItem" Src="~/Views/Header/MainMenuItemControl.ascx" %>
<div id="MainMenu">
    <table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <%   
            foreach (MenuItem mi in Model.Items)
            {
                string x = Model.Items.IndexOf(mi).ToString();
        %>
        <td>
            <%= x %>  <<-- THIS GETS RESOLVED TO 0,1,2,3,4,...
            <DDLControls:MainMenuItem ItemIndex="<% x %>" runat="server" />  <<-- THIS DOESN'T GET RESOLVED
        </td>
        <%

            } 
        %>
    </tr>
</table>
</div>

1 Answer 1

2

You need to add the Bindable attribute to your property:

[System.ComponentModel.Bindable(true)]
public string SomeValue 
{
    get
    {
        return someValue;
    }
    set
    {
        someValue = value;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Is there something more that needs to be done with the calling code?

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.