不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
cs页中引用的命名空间无法在aspx页中使用的一点解释
编辑:dnawo 日期:2008-09-18
在我新建的类库中有个MzwuCom.Common命名空间,其下有个Input类,代码为:
然后我在站点中添加了对这个类库项目的引用,并在Default.aspx.cs中使用Input.CutStr:
运行正常,一切看起来挺正常的,下边我们试试看在aspx页中使用Input.CutStr:
运行出错:当前上下文中不存在名称“Input”!Why?问题暂且放在一边,我们做个让人惊奇的小实验:
运行结果:
引用内容
My God!这说明在运行的时候aspx页被动态生成为_Default类的一个子类ASP.default_aspx[1]!OK,那这就不难解释为什么在aspx页中不能使用Input.CutStr了[2],如果一定非要使用的话可改成如下形式:
[1]aspx中第一行:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" TraceMode="SortByCategory" Trace="false" %>
这已经表明aspx将会是_Default的子类。
[2].父类中引用的命名空间如果在子类中要使用必须重新引用。
2008-09-18补充:上边的问题也只在代码分离时会出现,不使用代码分离时运行正常。
参考文章:
1.aspx页面在运行的时候会自动产生当前页面类的一个子类
复制内容到剪贴板
程序代码

using System;
using System.Collections.Generic;
using System.Text;
namespace MzwuCom.Common
{
public class Input
{
/// <summary>
/// 字符串截取
/// </summary>
/// <param name="strTemp"></param>
/// <param name="length"></param>
public static string CutStr(string strTemp,int length)
{
if (length > strTemp.Length)
return strTemp.Substring(0);
else
return strTemp.Substring(0, length);
}
}
}
using System.Collections.Generic;
using System.Text;
namespace MzwuCom.Common
{
public class Input
{
/// <summary>
/// 字符串截取
/// </summary>
/// <param name="strTemp"></param>
/// <param name="length"></param>
public static string CutStr(string strTemp,int length)
{
if (length > strTemp.Length)
return strTemp.Substring(0);
else
return strTemp.Substring(0, length);
}
}
}
然后我在站点中添加了对这个类库项目的引用,并在Default.aspx.cs中使用Input.CutStr:
复制内容到剪贴板
程序代码

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;
using MzwuCom.Common;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Input.CutStr("abcdef",2));
}
}
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;
using MzwuCom.Common;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Input.CutStr("abcdef",2));
}
}
运行正常,一切看起来挺正常的,下边我们试试看在aspx页中使用Input.CutStr:
复制内容到剪贴板
程序代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" TraceMode="SortByCategory" Trace="false" %>
<!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>Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(Input.CutStr("abcdef", 2)); %>
</div>
</form>
</body>
</html>
<!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>Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(Input.CutStr("abcdef", 2)); %>
</div>
</form>
</body>
</html>
运行出错:当前上下文中不存在名称“Input”!Why?问题暂且放在一边,我们做个让人惊奇的小实验:
复制内容到剪贴板
程序代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" TraceMode="SortByCategory" Trace="false" %>
<!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>Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
当前页面类型:<% Response.Write(this.GetType()); %><br />
父类型:<% Response.Write(this.GetType().BaseType); %>
</div>
</form>
</body>
</html>
<!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>Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
当前页面类型:<% Response.Write(this.GetType()); %><br />
父类型:<% Response.Write(this.GetType().BaseType); %>
</div>
</form>
</body>
</html>
运行结果:

当前页面类型:ASP.default_aspx
父类型:_Default
父类型:_Default
My God!这说明在运行的时候aspx页被动态生成为_Default类的一个子类ASP.default_aspx[1]!OK,那这就不难解释为什么在aspx页中不能使用Input.CutStr了[2],如果一定非要使用的话可改成如下形式:
复制内容到剪贴板
程序代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" TraceMode="SortByCategory" Trace="false" %>
<!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>Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(MzwuCom.Common.Input.CutStr("abcdef", 2)); %><br />
</div>
</form>
</body>
</html>
<!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>Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(MzwuCom.Common.Input.CutStr("abcdef", 2)); %><br />
</div>
</form>
</body>
</html>
[1]aspx中第一行:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" TraceMode="SortByCategory" Trace="false" %>
这已经表明aspx将会是_Default的子类。
[2].父类中引用的命名空间如果在子类中要使用必须重新引用。
2008-09-18补充:上边的问题也只在代码分离时会出现,不使用代码分离时运行正常。
复制内容到剪贴板
程序代码

<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="MzwuCom.Common" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Input.CutStr("abcdef",2));
}
</script>
<!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>Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(Input.CutStr("abcdef", 2)); %><br />
</div>
</form>
</body>
</html>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="MzwuCom.Common" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Input.CutStr("abcdef",2));
}
</script>
<!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>Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(Input.CutStr("abcdef", 2)); %><br />
</div>
</form>
</body>
</html>
参考文章:
1.aspx页面在运行的时候会自动产生当前页面类的一个子类
评论: 0 | 引用: 0 | 查看次数: 5146
发表评论
请登录后再发表评论!