私のデザイン部分では、すべてのラベルとドロップダウンリストを追加しましたが、register.aspx.csでは、これらのコントロールが現在のコンテキストに存在しないことを示しています。
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
public partial class register : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server = .\\SQLEXPRESS;AttachDbFileName =|DataDirectory|\\Database123.mdf;trusted_connection = true;USER Instance =yes");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
try
{
if (CheckBox1.Checked == true)
{
String f;
f = Path.GetFileName(FileUpload1.FileName);
con.Open();
if (f != "")
{
FileUpload1.SaveAs(Server.MapPath("~") + "/images/" + f);
Label2.Text = "~" + "/images/" + f;
SqlCommand cmd1 = new SqlCommand("insert into register values('" + TextBox1.Text + "','" + TextBox8.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + RadioButtonList1.SelectedValue + "','" + TextBox4.Text + "','" + DropDownList3.SelectedItem + "','" + DropDownList2.SelectedItem + "','" + TextBox7.Text + "','" + TextBox10.Text + "','" + RadioButtonList2.SelectedValue + "','" + TextBox12.Text + "','" + Label2.Text + "','" + DropDownList1.Text + "','" + TextBox14.Text + "')", con);
cmd1.ExecuteNonQuery();
TextBox1.Text = " ";
TextBox8.Text = " ";
TextBox2.Text = " ";
TextBox3.Text = " ";
TextBox4.Text = " ";
// TextBox15.Text = " ";
// TextBox16.Text = " ";
TextBox7.Text = " ";
TextBox10.Text = " ";
TextBox12.Text = " ";
TextBox14.Text = " ";
Label1.Visible = true;
Label1.Text = "submitted successfully";
}
else
{
SqlCommand cmd1 = new SqlCommand("insert into register(user_id,password,fname,lname,user_type,address,city,state,pin,contact_no,gender,email,seq_que,seq_ans) values('" + TextBox1.Text + "','" + TextBox8.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + RadioButtonList1.SelectedValue + "','" + TextBox4.Text + "','" + DropDownList3.SelectedItem + "','" + DropDownList2.SelectedItem + "','" + TextBox7.Text + "','" + TextBox10.Text + "','" + RadioButtonList2.SelectedValue + "','" + TextBox12.Text + "','" + DropDownList1.Text + "','" + TextBox14.Text + "')", con);
cmd1.ExecuteNonQuery();
TextBox1.Text = " ";
TextBox8.Text = " ";
TextBox2.Text = " ";
TextBox3.Text = " ";
TextBox4.Text = " ";
// TextBox15.Text = " ";
//TextBox16.Text = " ";
TextBox7.Text = " ";
TextBox10.Text = " ";
TextBox12.Text = " ";
TextBox14.Text = " ";
Label1.Visible = true;
Label1.Text = "submitted successfully";
}
con.Close();
}
else
{
Label1.Visible = true;
Label1.Text = " terms & condition must checked";
}
}
catch (Exception e1)
{
Response.Write("<script language='javascript'>alert(\"Invalid Data Entry\")</script>");
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedIndex == 1)
{
DropDownList3.Items.Clear();
DropDownList3.Items.Add("jaipur");
DropDownList3.Items.Add("udaipur");
DropDownList3.Items.Add("ajmer");
DropDownList3.Items.Add("bharatpur");
DropDownList3.Items.Add("tonk");
}
else if (DropDownList2.SelectedIndex == 2)
{
DropDownList3.Items.Clear();
DropDownList3.Items.Add("amravati");
DropDownList3.Items.Add("mumbai");
}
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
}
}