如何调用code变量后面的aspx页面 [英] how to call a variable in code behind to aspx page

查看:89
本文介绍了如何调用code变量后面的aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我已经看到了这,但不能记得做它的正确途径...基本上,我有所谓的串客在我的cs文件的字符串变量..但我是不是能够通过它我的aspx页面像

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 to pass it to my aspx page something like

<%=clients%>  

请纠正我,我不记得或不知道如何做到这一点。 (新C#),当我GOOGLE了它..还不清楚..或者没有多少这些那里..作为搜索

please correct me, i do not recall or not sure how to do this. (new to c#) and when i googled it.. it was not clear.. or not many of these out there.. searched as

asp.net C#&LT;%=%GT; 不是一致的结果..也许是因为我不知道如何调用这些..

"asp.net c# <%= %> not consistent results.. maybe because i do not know how to call these..

推荐答案

字段必须声明公共从ASPX标记正确的知名度。在任何情况下,你可以声明一个属性:

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.

然后,把它在ASPX端:

Then, to call it on the ASPX side:

&LT;%=客户端%>

<%=Clients%>

请注意,如果你把它放在一台服务器标记属性这是不行的。例如:

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

&LT; ASP:标签=服务器文本=&LT;%=客户端%>/>

<asp:Label runat="server" Text="<%=Clients%>" />

这是无效的。这是:

&LT; D​​IV>&LT;%=客户端%>&LT; / DIV>

<div><%=Clients%></div>

这篇关于如何调用code变量后面的aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆