<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Security.aspx.cs" Inherits="myClasses.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <a href="Security.aspx?id=<%=myhello.jm(kk)%>">点我</a></div>
    </form>
</body>
</html>
不存在"myhello"但在Security.aspx.cs里用myhello.jm就没有问题,请问在这个页面要怎么引用?

解决方案 »

  1.   

    学习~
    猜测:类myhello的私有的?
      

  2.   

    <a   href="Security.aspx?id= <%# 命名空间.myhello.jm(kk)%> "> 点我 </a> 
    要加命名空间,myhello 要为public
      

  3.   

    1.非static方法..在当前页中实例化一个myhello,public类型的..
    2.static方法..带上完整的命名空间
      

  4.   

    全部代码如下:如果在cs里用就没问题using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using myclass.SayHello;
    namespace myClasses
    {
        public partial class Security : System.Web.UI.Page
        {
            public string kk;
            public void Page_Load(object sender, EventArgs e)
            {
                TSayHello myhello = new TSayHello();            kk = "1234567890";            if (Request["id"] != null)
                {
                    Response.Write(myhello.zm(Request["id"]));
                }
            }    }
    }
    上面用了一个"myhello.zm"  在这里没问题,下面是在aspx里也使用自定义类,会提示找不到:
    我想在aspx页面也用一个"myhello.jm"     (已经在类中定义好的了)
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Security.aspx.cs" Inherits="myClasses.Security" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <a href="Security.aspx?id=<%=myhello.jm(kk)%>">点我</a></div>
        </form>
    </body>
    </html>上面这个"myhello.jm" 老是提示不存在,要怎么引用呢?我试过加命名空间但不对.我的类都是用public 定义的....
      

  5.   

    当然找不到啦,Security 类中,根本没有声明这个类的对象(如果是private的话,应暴露它)
    有二个方法,在类中声明这个类的对象,还有就是将这个类的方法声明为static
      

  6.   

    myhello都沒有聲明啊,試試下面的做法namespace   myClasses 

            public   partial   class   Security   :   System.Web.UI.Page 
            { 
                    public   string   kk; 
                    public TSayHello   myhello;
                    public   void   Page_Load(object   sender,   EventArgs   e) 
                    { 
                            myhello   =   new   TSayHello();                         kk   =   "1234567890";                         if   (Request["id"]   !=   null) 
                            { 
                                    Response.Write(myhello.zm(Request["id"])); 
                            } 
                    }         } 
      

  7.   

    行啊,这样聲明不会提示myhello不存在了,但好像myhello就不能引用myhello.jm()了,它提示myhello为空了....
      

  8.   

    改成如下,OKnamespace   myClasses 

            public   partial   class   Security   :   System.Web.UI.Page 
            { 
                    public   string   kk; 
                    public TSayHello   myhello =   new   TSayHello();
                    public   void   Page_Load(object   sender,   EventArgs   e) 
                    {                         kk   =   "1234567890";                         if   (Request["id"]   !=   null) 
                            { 
                                    Response.Write(myhello.zm(Request["id"])); 
                            } 
                    }         } 
      

  9.   

    我晕~  我上个厕所的工夫,分就没了。郁闷~行啊,这样聲明不会提示myhello不存在了,但好像myhello就不能引用myhello.jm()了,它提示myhello为空了.... 
    -------------------------------------------------------------------------------------
    用类名引用,也就是TSayHello.jm();  jm为static方法