2012-06-19 25 views
0

在我的設計部分,我添加了所有的標籤和下拉列表,但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) 
    { 

    } 
    } 
+0

請提供aspx文件,並刪除除1個文本框以外的所有代碼,以便更容易地進行幫助和調試。 – CodingBarfield

回答

0

如果你已經正確指定了page指令中的文件後面的代碼,並且仍然面對着sa我的問題,可能是你的頁面設計師(register.aspx.designer.cs)搞砸了。您可以刪除並重新創建它。

1)首先刪除register.aspx.designer.cs

2)然後右擊從Solution Explorer Web項目,並選擇選項Convert to Web Application(這將重新創建desginer.cs;現在它應該工作的罰款)

+0

謝謝prashanth ..現在它正在工作。 – user949914

+0

@ user949914很好。供參考:如果它回答你的問題,你可以將其標記爲答案。 –

0

確保您的Aspx頁面正確設置了CodeFileInherits屬性。

.aspx的:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="register" %> 

代碼隱藏:

public partial class register : System.Web.UI.Page {} 
1

入住遠日點的回答中提到的aspx頁面 在繼承財產 並確保標籤的aspx頁面上正確關閉

+0

不錯....... –

0

如果您從不同版本的vs複製元素並將其粘貼到您的應用程序,則可能會遇到此問題。只需刪除這些元素並使用工具箱將它們添加回

相關問題