HTML按钮不会触发,也不会调用服务器端,也不会保存在数据库中 那我该怎么办
<div class="container-contact2">
<div class="wrap-contact2">
<form class="contact2-form validate-form">
<span class="contact2-form-title">
Patient Info
</span>
<div class="wrap-input2 validate-input" data-validate="Name is required">
<asp:TextBox ID="fname" CssClass="input2" runat="server"></asp:TextBox>
<span class="focus-input2" data-placeholder="First NAME"></span>
</div>
<div class="wrap-input2 validate-input" data-validate="Name is required">
<asp:TextBox CssClass="input2" ID="lname" runat="server" ></asp:TextBox>
<span class="focus-input2" data-placeholder="Last NAME"></span>
</div>
<div class="wrap-input2 validate-input" data-validate="Name is required">
<asp:TextBox CssClass="input2" ID="Address" runat="server"></asp:TextBox>
<span class="focus-input2" data-placeholder="Address"></span>
</div>
<div class="wrap-input2 validate-input" data-validate="Name is required">
<asp:TextBox ID="city" CssClass="input2" runat="server"></asp:TextBox>
<span class="focus-input2" data-placeholder="City"></span>
</div>
<label class="custom-sel ">
<select id="gender" runat="server" name='options'>
<option >Male </option>
<option >Female</option>
</select>
</label>
<div class="wrap-input2 validate-input" data-validate = "Valid email is required: ex@abc.xyz">
<label class="label" for="dateofbirth">Date Of Birth</label>
<input class="input" runat="server" type="date" name="dateofbirth" id="birth">
<span class="focus-input2" data-placeholder=""></span>
</div>
<div class="wrap-input2 validate-input" data-validate="Name is required">
<input class="input2" id="ssec" runat="server" type="text" name="name">
<span class="focus-input2" data-placeholder="Social Security"></span>
</div>
<label class="custom-sel ">
<select id="inppSel" runat="server" name='options'>
</select>
<input runat="server" type="hidden" id="inpTxt"/>
</label>
<div class="container-contact2-form-btn">
<div class="wrap-contact2-form-btn">
<div class="contact2-form-bgbtn"></div>
<asp:Button ID="Button1" OnClick="saveChanges" runat="server" Text="Button" />
</div>
</div>
</form>
</div>
</div>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
代码:
DataBaseConnection db = new DataBaseConnection();
db.disconnect();
string sql1 = "insert into TBL_Persons values( @First_Name,@Last_Name,@Address,@City)";
SqlCommand cmd1 = new SqlCommand(sql1, db.connect());
cmd1.Parameters.AddWithValue("@First_Name",fname.Text);
cmd1.Parameters.AddWithValue("@Last_Name", lname.Text);
cmd1.Parameters.AddWithValue("@Address", Address.Text);
cmd1.Parameters.AddWithValue("@City", city.Text);
cmd1.ExecuteNonQuery();
string sql2 = "Insert into TBL_Patients values(@Gender,@Date_OF_Birth, @Social_Security,@Person_ID, @Case_ID)";
db.disconnect();
string sql3 = "select max(Person_ID) from TBL_Persons ";
SqlCommand cmd2 = new SqlCommand(sql3, db.connect());
int max = (int)(cmd2.ExecuteScalar());
db.disconnect();
SqlCommand cmd3 = new SqlCommand(sql2, db.connect());
cmd3.Parameters.AddWithValue("@Gender", gender.Items[gender.SelectedIndex].Text);
cmd3.Parameters.AddWithValue("@Date_OF_Birth", birth.Value);
cmd3.Parameters.AddWithValue("@Social_Security", ssec.Value);
cmd3.Parameters.AddWithValue("@Person_ID", max);
cmd3.Parameters.AddWithValue("@Case_ID", inpTxt.Value);
cmd3.ExecuteNonQuery();
Label1.Text = "Patient Saved";
答案 0 :(得分:0)
`
String multilineError = "Multiline Error \n Next Line \n Third line \n Fourth line";
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (TextUtils.isEmpty(edtName.getText().toString())) {
edtName.setError(multilineError);
}
}
});
function saveChanges()
{
PageMethods.save();
}
<asp:Button ID="Button1" OnClick="saveChanges(); " runat="server" Text="Button" />