当我在填写表单后按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);
}
答案 0 :(得分:1)
用OnClick替换 onClickButton :
示例:
<asp:Button id="Button1"
Text="Submit"
OnClick="SubmitBtn_Click"
runat="server"/>