当我按下提交按钮时,asp.net中的按钮没有任何功能?

时间:2019-05-04 01:04:07

标签: c# asp.net sql-server

当我在填写表单后按Submit(提交)按钮时,表单将刷新,但数据未提交到数据库中,并且我正尝试使用存储过程来存储数据。 谢谢

[按钮代码]

 <div class="col-xs-12 col-sm-12 text-center">
     <asp:Button ID="Submit_Button" class="btn btn-info btn-md" runat="server" onClickButton="Submit_Form_Click" Text="Submit" />
 </div>

[ASP.NET背后的代码]

 protected void Submit_Form_Click(object sender, EventArgs e)
 {
      string Sponsirship_TypeValue = Sponsirship_Type.SelectedValue;
      string Select_Gender = Gender.SelectedValue;
      string Marital_Status = MaritalStatus.SelectedValue;
      string connStr = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
      SqlConnection con = new SqlConnection(connStr);
      con.Open();
      SqlCommand cmd = new SqlCommand("sp_Student_Registration", con);
      cmd.CommandType = CommandType.StoredProcedure;
      SqlParameter paramReg_Num = new SqlParameter("@PHD_Registration_Number", Session["LoginUserName"]);
      SqlParameter paramSponsirship_Type = new SqlParameter("@SponsershipType", Sponsirship_TypeValue);
      cmd.ExecuteNonQuery();

      int result = cmd.ExecuteNonQuery();

      Response.Write("Number of Changes" + result);
 }

1 个答案:

答案 0 :(得分:1)

OnClick替换 onClickButton

示例:

<asp:Button id="Button1"
           Text="Submit"
           OnClick="SubmitBtn_Click" 
           runat="server"/>