how to call a variable in code behind to aspx page

后端 未结 9 1935
暗喜
暗喜 2020-11-27 07:06

i know i have seen this but cant recall the correct way of doing it... basically i have a string variable called \"string clients\" in my .cs file.. but i wasn\'t to be able

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 07:25

    You can access a public/protected property using the data binding expression <%# myproperty %> as given below:

        
    

    you should call DataBind method, otherwise it can't be evaluated.

        public partial class WebForm1 : System.Web.UI.Page
        {
         public string CodeBehindVarPublic { get; set; }
          protected void Page_Load(object sender, EventArgs e)
            {
              CodeBehindVarPublic ="xyz";
           //you should call the next line  in case of using <%#CodeBehindVarPublic %>
    
              DataBind();
            }
    

    }

提交回复
热议问题