分析器错误消息: “Responsedirect.WebForm1”不扩展类“System.Web.UI.Page”,因此此处不允许。源错误:
行 1: <%@ Page Language ="C#" Codebehind ="WebForm1.aspx.cs"
行 2: AutoEventWireup="false" Inherits="Responsedirect.WebForm1" %>
行 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
源文件: /WebForm1.aspx 行: 1
行 1: <%@ Page Language ="C#" Codebehind ="WebForm1.aspx.cs"
行 2: AutoEventWireup="false" Inherits="Responsedirect.WebForm1" %>
行 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
源文件: /WebForm1.aspx 行: 1
是指你class的名字
比如你的.cs文件里面的class 是_default Inherits="_Default"
public partial class _Default : System.Web.UI.Page
{
把你的改成class名字就可以了
<%@ Page Language ="C#" Codebehind ="WebForm1.aspx.cs"
行 2: AutoEventWireup="false" Inherits="Responsedirect.WebForm1" %>
行 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
行 2: AutoEventWireup="false" Inherits="WebForm1" %>
行 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="WebForm1.aspx.cs"
Inherits="ResponseRedirect.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>WebForm1</title>
</head>
<body ms_positioning="gridlayout">
<form id="Form1" method="post" runat="server">
请输入要访问的网址:<asp:TextBox ID="TextBox1" runat="server"
width="368px" ></asp:TextBox>
<p></p>
<asp:Button ID="Button1" runat="server" Text = "访问" ></asp:Button></form>
</body>
</html>.cs文件内容namespace WebApplication5
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected void Page_Load(object sender, EventArgs e)
{ }
private void Button1_Click(object sender, System.EventArgs e)
{
if((TextBox1.Text != "") &&
(TextBox1.Text.IndexOf("http://")>=0))
{
//如果目标网址不为空,并包含“http://”字符,则跳转
Response.Redirect(TextBox1.Text);
} }
}
}
Inherits="WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>WebForm1 </title>
</head>
<body ms_positioning="gridlayout">
<form id="Form1" method="post" runat="server">
请输入要访问的网址: <asp:TextBox ID="TextBox1" runat="server"
width="368px" > </asp:TextBox>
<p> </p>
<asp:Button ID="Button1" runat="server" Text = "访问" > </asp:Button>
</form>
</body>
</html> .cs文件内容 namespace WebApplication5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected void Page_Load(object sender, EventArgs e)
{ }
private void Button1_Click(object sender, System.EventArgs e)
{
if((TextBox1.Text != "") &&
(TextBox1.Text.IndexOf("http://")>=0))
{
//如果目标网址不为空,并包含“http://”字符,则跳转
Response.Redirect(TextBox1.Text);
} }
}
}
Inherits="ResponseRedirect.WebForm1" %>
改成
<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication5.WebForm1" %>
试试
检查页面的命名空间和class的命名空间是不是一样,确保相同就OK了