0
0 举个例子:我用vs2008编译<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cookie.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 id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="1" style="width: 40%">
<tr>
<td colspan="2" style="text-align: center">
用户登录</td>
</tr>
<tr>
<td>
用户名:</td>
<td >
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox></td>
</tr>
<tr>
<td>
密 码:</td>
<td >
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td width="34%">
Cookie有效期:</td>
<td style="width: 336px"><asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Selected="True">1天</asp:ListItem>
<asp:ListItem Value="2">1个月</asp:ListItem>
<asp:ListItem Value="3">半年</asp:ListItem>
<asp:ListItem Value="4">1年</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnlog" runat="server" Text="登录" OnClick="btnlog_Click" />
<asp:Button ID="btnreg" runat="server" Text="注册" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>CS代码:using System;
using System.Data;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnlog_Click(object sender, EventArgs e)
{
string name = "admin";
string pass = "admin";
if (this.TextBox1.Text == "admin" && this.TextBox2.Text == "admin")
{
if (this.RadioButtonList1.SelectedValue.ToString() == "1")
{
this.Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(1);
this.Response.Cookies["Password"].Expires = DateTime.Now.AddDays(1);
}
if (RadioButtonList1.SelectedValue.ToString() == "2")
{
this.Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(1);
this.Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(1);
}
if (RadioButtonList1.SelectedValue.ToString() == "3")
{
this.Response.Cookies["UserName"].Expires = DateTime.Now.AddYears(1 / 2);
this.Response.Cookies["Password"].Expires = DateTime.Now.AddYears(1 / 2);
}
if (RadioButtonList1.SelectedValue.ToString() == "4")
{
this.Response.Cookies["UserName"].Expires = DateTime.Now.AddYears(1);
this.Response.Cookies["Password"].Expires = DateTime.Now.AddYears(1);
}
this.Response.Cookies["UserName"].Value = this.TextBox1.Text;
this.Response.Cookies["Password"].Value = this.TextBox2.Text;
Response.Redirect("getcookie.aspx");
}
else
{
Response.Redirect("cookie.aspx");
} }
}调试没有问题 能正常运行但是我用同样的方法放到vs 2010调试时就出现下面的错误错误 3 “_Default”不包含“TextBox1”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“TextBox1”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 22 18 WebApplication1
错误 4 “_Default”不包含“TextBox2”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“TextBox2”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 22 51 WebApplication1
错误 5 “_Default”不包含“RadioButtonList1”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“RadioButtonList1”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 24 22 WebApplication1
错误 6 当前上下文中不存在名称“RadioButtonList1” D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 29 17 WebApplication1
错误 7 当前上下文中不存在名称“RadioButtonList1” D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 34 17 WebApplication1
错误 8 当前上下文中不存在名称“RadioButtonList1” D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 39 17 WebApplication1
错误 9 “_Default”不包含“TextBox1”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“TextBox1”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 44 60 WebApplication1
错误 10 “_Default”不包含“TextBox2”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“TextBox2”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 45 60 WebApplication1但是我继续调试一样可以运行而且效果是一样的 没有任何问题麻烦哪位指教下小弟感激不尽~谢谢!
0 举个例子:我用vs2008编译<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cookie.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 id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="1" style="width: 40%">
<tr>
<td colspan="2" style="text-align: center">
用户登录</td>
</tr>
<tr>
<td>
用户名:</td>
<td >
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox></td>
</tr>
<tr>
<td>
密 码:</td>
<td >
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td width="34%">
Cookie有效期:</td>
<td style="width: 336px"><asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Selected="True">1天</asp:ListItem>
<asp:ListItem Value="2">1个月</asp:ListItem>
<asp:ListItem Value="3">半年</asp:ListItem>
<asp:ListItem Value="4">1年</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnlog" runat="server" Text="登录" OnClick="btnlog_Click" />
<asp:Button ID="btnreg" runat="server" Text="注册" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>CS代码:using System;
using System.Data;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnlog_Click(object sender, EventArgs e)
{
string name = "admin";
string pass = "admin";
if (this.TextBox1.Text == "admin" && this.TextBox2.Text == "admin")
{
if (this.RadioButtonList1.SelectedValue.ToString() == "1")
{
this.Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(1);
this.Response.Cookies["Password"].Expires = DateTime.Now.AddDays(1);
}
if (RadioButtonList1.SelectedValue.ToString() == "2")
{
this.Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(1);
this.Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(1);
}
if (RadioButtonList1.SelectedValue.ToString() == "3")
{
this.Response.Cookies["UserName"].Expires = DateTime.Now.AddYears(1 / 2);
this.Response.Cookies["Password"].Expires = DateTime.Now.AddYears(1 / 2);
}
if (RadioButtonList1.SelectedValue.ToString() == "4")
{
this.Response.Cookies["UserName"].Expires = DateTime.Now.AddYears(1);
this.Response.Cookies["Password"].Expires = DateTime.Now.AddYears(1);
}
this.Response.Cookies["UserName"].Value = this.TextBox1.Text;
this.Response.Cookies["Password"].Value = this.TextBox2.Text;
Response.Redirect("getcookie.aspx");
}
else
{
Response.Redirect("cookie.aspx");
} }
}调试没有问题 能正常运行但是我用同样的方法放到vs 2010调试时就出现下面的错误错误 3 “_Default”不包含“TextBox1”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“TextBox1”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 22 18 WebApplication1
错误 4 “_Default”不包含“TextBox2”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“TextBox2”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 22 51 WebApplication1
错误 5 “_Default”不包含“RadioButtonList1”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“RadioButtonList1”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 24 22 WebApplication1
错误 6 当前上下文中不存在名称“RadioButtonList1” D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 29 17 WebApplication1
错误 7 当前上下文中不存在名称“RadioButtonList1” D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 34 17 WebApplication1
错误 8 当前上下文中不存在名称“RadioButtonList1” D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 39 17 WebApplication1
错误 9 “_Default”不包含“TextBox1”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“TextBox1”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 44 60 WebApplication1
错误 10 “_Default”不包含“TextBox2”的定义,并且找不到可接受类型为“_Default”的第一个参数的扩展方法“TextBox2”(是否缺少 using 指令或程序集引用?) D:\Documents and Settings\long xiang\my documents\visual studio 2010\projects\WebApplication1\WebApplication1\cookie.aspx.cs 45 60 WebApplication1但是我继续调试一样可以运行而且效果是一样的 没有任何问题麻烦哪位指教下小弟感激不尽~谢谢!
解决方案 »
- 如何屏蔽a样式在网页某些地方不显示
- 求救呀!asp.net button_clik()没有反应搞了一天没找到原因,。
- 今天开始学习2005,Aspx 2.0,所有分求快速入门方法
- 如何防止数据库被恶意注入
- 问一个问题,大家平时做饼图或柱图都是采用什么方法的?
- http 403 (禁止访问)
- 求救!!!!有谁知道<a href="#北京">北京</a>里面的 ="#北京"是什么意思啊?
- 在win2000、98下如何得到硬盘物理的序列号!(非逻辑序列号)~(比较难)
- 怎么将文件保存到MSSQL数据库中?我用的C#!急急急急急!
- gridview如何只显示本用户登录的信息
- JS掉用隐藏域问题
- 向各位前辈请教一个ASP.NET中异步操作问题
而你vs2010 中界面是这个cookie.aspx 而后台还是这个_Default 改为_cookie
试试