我在前台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() %>

解决方案 »

  1.   

    public string test()????.cs是这样写的?
      

  2.   

    后台代码如下public string test()
        {
            return "jjj";
        }
      

  3.   

    如果你要这么写的话应该是先用变量拿到这个方法的返回值,再<%=返回值 %>
      

  4.   

    public string test() { return "jjj"; } 
    这样写是完全可以的。你的cs是那个页面的aspx.cs吗?
      

  5.   

    后台是public的方法的话,前台用<%#%>
    是变量的话,前台<%=%>
    <td width="95" class="user_red_title">个人信息
          <%#test() %>
    public string test()

        return "jjj"; 

      

  6.   


    一、第一种情况
    后台是全局的public变量的话,如下
    public string s = "abc";
    前台调用的话这样:
    <%=s %>二、第二种情况
    后台是public方法的话,如下
    public string test()

        return "jjj"; 

    前台调用的话这样:
    <%#test()%>
    这下你应该记得很清楚了吧
      

  7.   

    还是你代码的问题。不可能不行啊
    <%@ 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>
      

  8.   

    前台:
    <%=test() %>后台:
    public string test()
    {
         return "jjj";
    }重新编译解决方案后再运行~
      

  9.   

    哦,我知道了你的那个是放在<td></td>标签内的吧??? 给你的这个td加上 runat="server",或是改用Label等服务器控件来做.
    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";
    }
      

  10.   

    那你就直接绑定个字段得了呗<%=test() %>public string test()
    {}