我试图让我的网络表单检查空文本框,然后验证它,提交到数据库然后打印它..但我似乎无法弄清楚如何连接这些方法以使其全部工作一个接一个一旦我点击提交按钮。我有检查它的代码,然后报告/验证它,但我需要在打印功能之前首先连接另一个方法(button1_click(),它是 default.aspx.cs 页面上的一个受保护的 void)。我将如何将它们连接在一起,一个接一个地工作?
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 = "";
}
}