Very simple and stupid question.
i have a page class
public partial class ProtectWayItem : System.Web.UI.UserControl
{
public int Count { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Count = 10;
}
}
and how i can set div id equal Count.
I mean something like:
<div id='<%# Count %>' > </div>
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You have to use = instead #
<div id='<%= Count %>' >
And if you want to call with the # sign then you need to call a DataBind() method..
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
DataBind();
}
here is what each expression means
- The <%= expressions are evaluated at
render time - The <%# expressions are evaluated at
DataBind() time and are not evaluated
at all if DataBind() is not called. - <%# expressions can be used as
properties in server-side controls.
<%= expressions cannot.
For a better understanding, please check out this link: The difference between <%= and <%# in ASP.NET
Method 2
<div id='<%= Count %>' > </div>
But you must remember this section must be in FORM section.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0