我正在實現一個小型網站,將從用戶接受輸入並與c#中的數據庫進行交互,但問題在於後面的代碼(.aspx中的代碼.cs文件)不會讀取.aspx文件中的任何元素,但我確實將.aspx文件的指令中的inherit屬性指定爲.aspx.cs文件。無法加載類型'HomePage.aspx.cs'
這是HomePage.aspx文件
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HomePage.aspx.cs" Inherits="HomePage.aspx.cs" %>
<!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:Label ID="lbl_username" runat="server" Text="Username: "></asp:Label>
<asp:TextBox ID="txt_username" runat="server"></asp:TextBox>
<asp:Label ID="lbl_password" runat="server" Text="Password: "></asp:Label>
<asp:TextBox ID="txt_password" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="btn_login" runat="server" Text="Login" onclick="login" />
</div>
</form>
</body>
</html>
這是HomePage.aspx.cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
public partial class HomePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void login(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("loginProcedure", conn);
cmd.CommandType = CommandType.StoredProcedure;
string username = txt_username.Text;
string password = txt_password.Text;
cmd.Parameters.Add(new SqlParameter("@username", username));
SqlParameter name = cmd.Parameters.Add("@password", SqlDbType.VarChar, 50);
name.Value = password;
// output parm
SqlParameter count = cmd.Parameters.Add("@count", SqlDbType.Int);
count.Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
if (count.Value.ToString().Equals("1"))
{
Response.Write("Passed");
}
else
{
Response.Write("Failed");
}
}
}
我得到這個錯誤無法加載類型「HomePage.aspx.cs ',那麼我該如何處理這樣的事件呢?
清潔和重建。也刪除你的Obj文件夾中的東西。 – Rex