我的 Button1_click 是服务器端代码,当按下按钮时,数据被提交到数据库中。我的 SubmitForm() 是客户端代码。当我按下名为 button1 的按钮时,如何让两者都工作?(我的提交按钮)。下面的代码仅在按下按钮时触发 Onclick 而 OnClientClick 不触发。
<asp:Button ID="Button1" runat="server" Onclick = "Button1_Click"
OnClientClick = "javascript:SubmitForm();return false"
Text="Submit" Width="98px"
/>
这是我的提交表单代码
function SubmitForm() {
if (document.getElementById("hawbtxt").value == "") {
alert("Please enter the HAWB (B/L)!");
return false;
}
if (document.getElementById("invrefpotxt").value == "") {
alert("Please enter the INV/REF/PO!");
return false;
}
if (document.getElementById("hppartnumtxt").value == "") {
alert("Please enter the HP PART NUM!");
return false;
}
if (document.getElementById("iecpartnumtxt").value == "") {
alert("Please enter the IEC PART NUM!");
return false;
}
if (document.getElementById("qtytxt").value == "") {
alert("Please enter the QUANTITY!");
return false;
}
if (document.getElementById("bulkstxt").value == "") {
alert("Please enter the BULKS!");
return false;
}
if (document.getElementById("boxplttxt").value == "") {
alert("Please enter the BOX/PLT!");
return false;
}
if (document.getElementById("rcvddatetxt").value == "") {
alert("Please enter the DATE!");
return false;
}
if (document.getElementById("statustxt").value == "") {
alert("Please enter the STATUS!");
return false;
}
if (document.getElementById("carriertxt").value == "") {
alert("Please enter the CARRIER!");
return false;
}
if (document.getElementById("shippertxt").value == "") {
alert("Please enter the SHIPPER!");
return false;
}
//create coo_bto_test.bat
var sText, s;
var fso = new ActiveXObject("Scripting.FileSystemObject");
alert("called");
if (!fso.FileExists("C:\\COO_BTO_Test.bat")) {
s = fso.CreateTextFile("C:\\COO_BTO_Test.bat", true);
sText = "@echo off";
s.WriteLine(sText);
sText = ":Lbl";
s.WriteLine(sText);
sText = "ECHO \"^XA^MD0^PRB^JVY^LL1760^LH%XL%,%YL%^FS \">> COO.TXT";
s.WriteLine(sText);
sText = "ECHO \"^FO66,08^BY2,2.0,32^BCN,N,N,N^SN%Sno0%,1,Y^FS \">> COO.TXT";
s.WriteLine(sText);
sText = "ECHO \"^FO66,48^AF,8,8^SN%Sno0%,1,Y^FS \">> COO.TXT";
s.WriteLine(sText);
sText = ":END";
s.WriteLine(sText);
sText = "ECHO \"^PQ1 \">> COO.TXT";
s.WriteLine(sText);
sText = "ECHO \"^XZ \">> COO.TXT";
s.WriteLine(sText);
sText = "REM MODE COM1 9600"
s.WriteLine(sText);
sText = "REM TYPE COO.TXT > COM1"
s.WriteLine(sText);
sText = "TYPE COO.TXT > LPT1"
s.WriteLine(sText);
}
}
function WriteToFile(sText) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\PRT_Test.bat", true);
s.WriteLine(sText);
s.Close();
}
这是我的 button1_click 代码
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();
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.Dispose();
}