<%@ 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就没有问题,请问在这个页面要怎么引用?
<!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就没有问题,请问在这个页面要怎么引用?
猜测:类myhello的私有的?
要加命名空间,myhello 要为public
2.static方法..带上完整的命名空间
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 定义的....
有二个方法,在类中声明这个类的对象,还有就是将这个类的方法声明为static
{
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"]));
}
} }
}
{
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"]));
}
} }
}
-------------------------------------------------------------------------------------
用类名引用,也就是TSayHello.jm(); jm为static方法