Venkat
Venkat

Reputation: 2186

Passing <%=value%> in user control (.ascx)

This is the ascx control in .aspx

<Menu:MNU ID="PMPHeaderMenu" runat="server" HiLiter="<%=h%>"></Menu:MNU>

in aspx.cs I have

  public int h = 1;
  ....
  ....
  h = 5;

in ascx.cs I have the HiLiter Property

   public string HiLiter { get; set; }

When I debug I get the value as <%=h%> for HiLiter when I expect it to be 5.

How will I pass the server side set value to the user control?

Upvotes: 3

Views: 1598

Answers (1)

PSK
PSK

Reputation: 17943

You can't use <%=%> for controls with runat="server" for setting properties, <%=%> is similar like Response.Write.

<%# %> (Data-binding expressions) can be used to fill control properties, but the control should be inside a data-binding container like GridView, DetailsView, FormView and Repeater.

In your case you should set the value of the property from the code behind (aspx.cs) page like following.

 PMPHeaderMenu.HiLiter = h;
 this.DataBind();

Upvotes: 4

Related Questions