我在前台aspx页面中调用后台CS文件中定义的方法。不管我方法定义为private还是public ,最后执行页面都给我的提示是Compiler Error Message: CS0103: The name 'test' does not exist in the current context
我在aspx中写成这样
<td width="95" class="user_red_title">个人信息
Line 45: <%=test() %>
我在aspx中写成这样
<td width="95" class="user_red_title">个人信息
Line 45: <%=test() %>
{
return "jjj";
}
这样写是完全可以的。你的cs是那个页面的aspx.cs吗?
是变量的话,前台<%=%>
<td width="95" class="user_red_title">个人信息
<%#test() %>
public string test()
{
return "jjj";
}
一、第一种情况
后台是全局的public变量的话,如下
public string s = "abc";
前台调用的话这样:
<%=s %>二、第二种情况
后台是public方法的话,如下
public string test()
{
return "jjj";
}
前台调用的话这样:
<%#test()%>
这下你应该记得很清楚了吧
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> public String test()
{
return "测试";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<%=test() %>
</body>
</html>
<%=test() %>后台:
public string test()
{
return "jjj";
}重新编译解决方案后再运行~
1、
<td width="95" class="user_red_title" runat="server">个人信息
<%#test() %>
</td>2、
<td width="95" class="user_red_title">个人信息
<asp:Label ID="Label1" runat="server" Text='<%#test()%>'</asp:Label>
</td>后台cs文件:
public string test()
{
return "jjj";
}
{}