how to call a variable in code behind to aspx page

后端 未结 9 1930
暗喜
暗喜 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:31

    The field must be declared public for proper visibility from the ASPX markup. In any case, you could declare a property:

    
    private string clients;
    public string Clients { get { return clients; } }
    
    

    UPDATE: It can also be declared as protected, as stated in the comments below.

    Then, to call it on the ASPX side:

    <%=Clients%>

    Note that this won't work if you place it on a server tag attribute. For example:

    This isn't valid. This is:

    <%=Clients%>

提交回复
热议问题