首页 新闻 会员 周边

vs 2008没有问题2010出错

0
悬赏园豆:10 [已关闭问题] 关闭于 2010-12-22 20:34

举个例子:

我用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

但是我继续调试一样可以运行而且效果是一样的 没有任何问题

麻烦哪位指教下小弟

感激不尽~谢谢!

龙翔~的主页 龙翔~ | 初学一级 | 园豆:190
提问于:2010-11-25 19:02
< >
分享
所有回答(4)
0

你建的是WebApplication,怎么命名空间都没有?如果直接拷贝到VS2010中的话可能是智能提示不能更新过来导致的...建议新建页面然后把代码拷贝到新页面...

三桂 | 园豆:3565 (老鸟四级) | 2010-11-25 22:08
0

这么长一般懒得看。

顾晓北 | 园豆:10844 (专家六级) | 2010-11-26 08:51
0

是不是用VS2010直接打开VS2008的项目,如果做升级会提示的,不升级也有提示。我有出现过问题。

Astar | 园豆:40805 (高人七级) | 2010-11-27 08:17
0

最好只复制内容,这样比较保险。

dinoy | 园豆:160 (初学一级) | 2010-11-30 18:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册