0

类型或命名空间定义,预期文件结尾

public partial class contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Button1_Click1(object sender, EventArgs e)
    {
        if (TextBox1.Text == "")
        {
            /* Label2.Text = "name is compulasry";*/
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('name is compulasry');", true);
        }
        else
        {
            SqlConnection con = new SqlConnection(@"Data Source=SYSTEM2\SQLEXPRESS;Initial Catalog=amresh;Integrated Security=True");
            SqlCommand cmd;
            con.Open();
            cmd = new SqlCommand("insert into Deatil values('"+ TextBox1.Text +"')", con);
            cmd.ExecuteNonQuery();
            ClearInputs(Page.Controls);
            con.Close();
        }

        void ClearInputs(ControlCollection ctrls)
        {
            foreach (Control ctrl in ctrls)
            {
                if (ctrl is TextBox)
                    ((TextBox)ctrl).Text = string.Empty;

                ClearInputs(ctrl.Controls);
            }
        }
    }
}
4

1 回答 1

0

You missed to close Button1_Click1. You're missing a }

protected void Button1_Click1(object sender, EventArgs e)
{
    if (TextBox1.Text == "")
    {
        /* Label2.Text = "name is compulasry";*/
        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('name is compulasry');", true);
    }
    else
    {
        SqlConnection con = new SqlConnection(@"Data Source=SYSTEM2\SQLEXPRESS;Initial Catalog=amresh;Integrated Security=True");
        SqlCommand cmd;
        con.Open();
        cmd = new SqlCommand("insert into Deatil values('"+ TextBox1.Text +"')", con);
        cmd.ExecuteNonQuery();
        ClearInputs(Page.Controls);
        con.Close();
    }
} // <-- This is missed

And you need to remove an extra } at the end

void ClearInputs(ControlCollection ctrls)
{
     foreach (Control ctrl in ctrls)
    {
        if (ctrl is TextBox)
            ((TextBox)ctrl).Text = string.Empty;
                ClearInputs(ctrl.Controls);
    }
}
} // <-- Remove this
于 2013-09-16T12:25:53.077 回答