ASPX:
<form id="form1" runat="server">
<%
int a = 25;
%>
<asp:Label ID="Label1" runat="server"
Text='<%#a %>'></asp:Label>
</form>
代码背后:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataBind();
}
}
错误:
当前上下文中不存在名称“a”
答案 0 :(得分:0)
找到解决方案:
ASPX:
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server"
Text="<%#a %>"></asp:Label>
</form>
代码背后:
public int a;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
a = 25;
DataBind();
}
}
答案 1 :(得分:0)
这种方式可行.. ASPX:
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
代码背后的代码:
public int a;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
a = 25;
Label1.Text=a.ToString();
}
}
答案 2 :(得分:0)
protected
成员,并从代码块中访问它们。