Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
144 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...