救助,照搬 书上代码APS.NET调试运行不正常
我是asp.net初学者,配置是WIN10 64位+VS2010完整版,代码都是照书上的例子抄的,编译软件没提示错误,也检查了无数遍,一字一句都是跟书上一样的,调试时,无论是EDGE、IE还是360安全浏览器,只能显示初始页面内容,但凡涉及到重定向时,就没有反应了,不按设定好的程序运行,Label控件也无法实时更新内容。请问一下,除了录入书上的代码,还需要做一些其它工作才能正常调试吗?
如:
Default.aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
Default.aspx.cs代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("下面是获取的Seession信息:");
Response.Write("<br>SessionID:"+Session.SessionID);
Response.Write("<br>Session的数量:" + Session.Count);
Response.Write("<br>Session的模式:" + Session.Mode);
Response.Write("<br>Session的有效期" + Session.Timeout);
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["username"] = TextBox1.Text;
Response.Redirect("Session.aspx");
}
}
Session.aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
Session.aspx.cs代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Session : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] != null)
{
Response.Write("通过Session对象获取到的信息:" + Session["username"]);
}
else
{
Response.Write("请在上一页的文本框中输入用户名");
}
}
}
无论我是否在 文本框里输入内容, 点 击按钮都只是刷新一下就完了,没有进入Session.aspx页面。请问,我该怎么办呢?