how to set contol property in asp.net

后端 未结 2 657
忘掉有多难
忘掉有多难 2020-12-11 11:56

Very simple and stupid question.

i have a page class

public partial class ProtectWayItem : System.Web.UI.UserControl
    {
        public int Count {         


        
相关标签:
2条回答
  • 2020-12-11 12:30

    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

    0 讨论(0)
  • 2020-12-11 12:42
    <div id='<%= Count %>' > </div>
    

    But you must remember this section must be in FORM section.

    0 讨论(0)
提交回复
热议问题