Я пытаюсь получить мою веб-форму для проверки пустых текстовых полей, затем проверить ее, отправить в базу данных и затем распечатать ее. Но я не могу понять, как подключить методы для создания все работает один за другим, как только я нажимаю кнопку отправки. У меня есть код, который его проверяет, затем сообщает/проверяет его, но мне нужно подключить другой метод (button1_click(), который является защищенным void на странице default.aspx.cs) сначала перед функцией печати. Как бы я мог соединить все это вместе, чтобы работать один за другим?Метод нажатия кнопки
function submitForm() {
if (document.getElementById("hawbtxt").value == "") {
alert("Please enter the HAWB (B/L)!");
return;
}
if (document.getElementById("invrefpotxt").value == "") {
alert("Please enter the INV/REF/PO!");
return;
}
if (document.getElementById("hppartnumtxt").value == "") {
alert("Please enter the HP PART NUM!");
return;
}
if (document.getElementById("iecpartnumtxt").value == "") {
alert("Please enter the IEC PART NUM!");
return;
}
if (document.getElementById("qtytxt").value == "") {
alert("Please enter the QUANTITY!");
return;
}
if (document.getElementById("bulkstxt").value == "") {
alert("Please enter the BULKS!");
return;
}
if (document.getElementById("boxplttxt").value == "") {
alert("Please enter the BOX/PLT!");
return;
}
if (document.getElementById("rcvddatetxt").value == "") {
alert("Please enter the DATE!");
return;
}
if (document.getElementById("statustxt").value == "") {
alert("Please enter the STATUS!");
return;
}
if (document.getElementById("carriertxt").value == "") {
alert("Please enter the CARRIER!");
return;
}
if (document.getElementById("shippertxt").value == "") {
alert("Please enter the SHIPPER!");
return;
}
//report
report = ""
report += "ID: " + document.getElementById("generateidtxt").value + "<br>" //generated id
report += "HAWB (B/L): " + document.getElementById("hawbtxt").value + "<br>"
report += "INV/REF/PO: " + document.getElementById("invrefpotxt").value + "<br>"
report += "HP PART NUM: " + document.getElementById("hppartnumtxt").value + "<br>"
report += "IEC PART NUM: " + document.getElementById("iecpartnumtxt").value + "<br>"
report += "QTY: " + document.getElementById("qtytxt").value + "<br>"
report += "BULKS: " + document.getElementById("bulkstxt").value + "<br>"
report += "BOX/PLT: " + document.getElementById("boxplttxt").value + "<br>"
report += "RCVD DATE: " + document.getElementById("rcvddatetxt").value + "<br>"
report += "STATUS: " + document.getElementById("statustxt").value + "<br>"
report += "CARRIER: " + document.getElementById("carriertxt").value + "<br>"
report += "SHIPPER: " + document.getElementById("shippertxt").value + "<p>"
document.open();
document.clear();
document.write(report);
document.close();
//print
if (confirm('Print Label?')) {
//code for button1_click?
window.print();
} else {
form1.reset();
}
}
Это ниже на странице Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("insert into John_IEP_Crossing_Dock_Shipment values('" + generateidtxt.Text + "','" + hawbtxt.Text + "','" + invrefpotxt.Text + "','" + hppartnumtxt.Text + "','" + iecpartnumtxt.Text + "','" + qtytxt.Text + "','" + bulkstxt.Text + "','" + boxplttxt.Text + "','" + rcvddatetxt.Text + "','" + statustxt.Text + "','" + carriertxt.Text + "','" + shippertxt.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
// Label1.Visible = true;
// Label1.Text = "Your DATA stored Successfully!";
generateidtxt.Text = "";
hawbtxt.Text = "";
invrefpotxt.Text = "";
hppartnumtxt.Text = "";
iecpartnumtxt.Text = "";
qtytxt.Text = "";
bulkstxt.Text = "";
boxplttxt.Text = "";
rcvddatetxt.Text = "";
statustxt.Text = "";
carriertxt.Text = "";
shippertxt.Text = "";
}
}
Есть ли причина не использовать *** RequiredFieldValidator control *** и *** параметризованный запрос ***? – Win