私はコードを書いています.Default.aspxというWebフォームがあり、Default.aspx.csというコードビハインドファイルがあり、それにいくつかのテキストボックス、ボタンなどが追加されています. ここで、University.cs という別の .cs アイテムを作成し、University.cs に Default.aspx を含めて、テキスト ボックスの値を使用したいと考えています。Default.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.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LoginAs_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void loginButton_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=d:\\CourseRegistration\\WebSite1\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True";
Int32 verify;
string query1 = "Select count(*) from LoginTable where ID='" + idBox.Text + "' and Password='" + passwordBox.Text + "' and Type='" + LoginAs.SelectedValue + "'";
SqlCommand cmd1 = new SqlCommand(query1, con);
con.Open();
verify = Convert.ToInt32(cmd1.ExecuteScalar());
con.Close();
if (verify > 0)
{
if (LoginAs.SelectedValue == "Administrator")
Response.Redirect("Admin.aspx");
else if (LoginAs.SelectedValue == "Student")
Response.Redirect("Student.aspx");
else if (LoginAs.SelectedValue == "Instructor")
Response.Redirect("Instructor.aspx");
}
else
{
idBox.Text = "";
LoginError.Visible = true;
}
}
}
この Default.aspx.cs ファイルではすべてのテキスト ボックス、ボタンなどを使用できますが、University.cs ファイルでは使用できません。Default.aspx.cs を使用して記述しようとしましたが、機能しませんでした。これについて何ができますか?
ありがとうございました