Javascript 当我将return放入onclientclick时,服务器端不工作
请帮帮我。我尝试了所有的解决方案,但都不起作用。 当我放置return success()时,OnclientClick函数起作用;但Onclick不起作用 我的OnClientClick函数:Javascript 当我将return放入onclientclick时,服务器端不工作,javascript,asp.net,onclick,onclientclick,Javascript,Asp.net,Onclick,Onclientclick,请帮帮我。我尝试了所有的解决方案,但都不起作用。 当我放置return success()时,OnclientClick函数起作用;但Onclick不起作用 我的OnClientClick函数: function success() { var no = document.getElementById('<%= tbcNo.ClientID %>').value; var qty = document.getElementById('<%= t
function success() {
var no = document.getElementById('<%= tbcNo.ClientID %>').value;
var qty = document.getElementById('<%= tbquantity.ClientID %>').value;
var rbVanilla = document.getElementById('<%= rbVanilla.ClientID %>').checked;
var rbPandan = document.getElementById('<%= rbPandan.ClientID %>').checked;
var rbMocha = document.getElementById('<%= rbMocha.ClientID %>').checked;
var rbUbe = document.getElementById('<%= rbUbe.ClientID %>').checked;
var rbS1 = document.getElementById('<%= rbS1.ClientID %>').checked;
var rbS2 = document.getElementById('<%= rbS2.ClientID %>').checked;
var rbS3 = document.getElementById('<%= rbS3.ClientID %>').checked;
if (!no) {
bootbox.dialog({
message: "Please input your phone number!",
title: "Warning",
buttons: {
success: {
label: "OK",
className: "btn-success",
callback: function () {
}
}
}
});
}
else if (isNaN(no)) {
bootbox.dialog({
message: "Please input a valid number!",
title: "Warning",
buttons: {
success: {
label: "Ok",
className: "btn-success",
callback: function () {
return true;
}
}
}
});
}
else if (no.length < 11) {
bootbox.dialog({
message: "Phone number must be 11 digits!",
title: "Warning",
buttons: {
success: {
label: "OK",
className: "btn-success",
callback: function () {
return true;
}
}
}
});
}
else if (no) {
if (!qty) {
bootbox.dialog({
message: "Please enter a quantity for your order.",
title: "Warning",
buttons: {
success: {
label: "OK",
className: "btn-success",
callback: function () {
return true;
}
}
}
});
}
else if (qty) {
if (rbVanilla && rbS1) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Vanilla" +
'<br />'+
'Puto Cake Size: Small' +
'<br />'+
'Price: 250 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 250 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
}
}
}
});
return false;
}
else if (rbMocha && rbS1) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Mocha" +
'<br />' +
'Puto Cake Size: Small' +
'<br />' +
'Price: 250 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 250 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
else if (rbPandan && rbS1) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Pandan" +
'<br />' +
'Puto Cake Size: Small' +
'<br />' +
'Price: 250 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 250 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
else if (rbUbe && rbS1) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Ube" +
'<br />' +
'Puto Cake Size: Small' +
'<br />' +
'Price: 250 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 250 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
//S2
else if (rbVanilla && rbS2) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Vanilla" +
'<br />' +
'Puto Cake Size: Medium' +
'<br />' +
'Price: 350 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 350 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
else if (rbMocha && rbS2) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Mocha" +
'<br />' +
'Puto Cake Size: Medium' +
'<br />' +
'Price: 350 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 350 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
else if (rbPandan && rbS2) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Pandan" +
'<br />' +
'Puto Cake Size: Medium' +
'<br />' +
'Price: 350 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 350 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
else if (rbUbe && rbS2) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Ube" +
'<br />' +
'Puto Cake Size: Medium' +
'<br />' +
'Price: 350 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 350 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
// S3
else if (rbVanilla && rbS3) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Vanilla" +
'<br />' +
'Puto Cake Size: Large' +
'<br />' +
'Price: 450 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 450 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
else if (rbMocha && rbS3) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Mocha" +
'<br />' +
'Puto Cake Size: Large' +
'<br />' +
'Price: 450 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 450 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
else if (rbPandan && rbS2) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Pandan" +
'<br />' +
'Puto Cake Size: Large' +
'<br />' +
'Price: 450 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 450 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
else if (rbUbe && rbS2) {
bootbox.dialog({
message: '<div style="text-align:center;">' +
"Puto Cake Flavor: Ube" +
'<br />' +
'Puto Cake Size: Large' +
'<br />' +
'Price: 450 Pesos' +
'<br/>' +
'Quantity: ' + qty +
'<br />' +
'Total Amount: ' + qty * 450 +
'<br/>' +
'We will call you at ' + '<b>' + no + '</b>' +
'<div>',
title: "Order Summary",
buttons: {
success: {
label: "That's Correct",
className: "btn-success",
callback: function () {
done();
}
},
danger: {
label: "That's Incorrect",
className: "btn-danger",
callback: function () {
return true;
}
}
}
});
return false;
}
}
}
else{
bootbox.dialog({
message: "The company will contact you shortly to further discuss the order that you made. Thank you for choosing Baby's Puto Cake!",
title: "Information",
buttons: {
success: {
label: "OK",
className: "btn-success",
callback: function () {
window.location = "Main.aspx";
document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
return true;
}
}
}
});
}
return false;
}
function done() {
bootbox.dialog({
message: "Would you like to process another order?",
title: "Order Verification",
buttons: {
success: {
label: "Yes",
className: "btn-success",
callback: function () {
}
},
danger: {
label: "No",
className: "btn-danger",
callback: function () {
done1();
}
}
}
});
}
function done1() {
bootbox.dialog({
message: "The company will contact you shortly to further discuss the order that you made. Thank you for choosing Baby's Puto Cake!",
title: "Information",
buttons: {
success: {
label: "OK",
className: "btn-success",
callback: function () {
window.location = "Main.aspx";
document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
}
}
}
});
}
我尝试过这个,但当我删除return false时。OnclientClick不工作。我还试着禁用按钮,但它仍然不起作用
有人能帮我吗。我真的很绝望。已经好几天没有解决问题了。OnClientClick=“return success();”应该可以工作,因为OnClientClick将首先执行javascript函数,如果没有出现错误,那么它将执行OnClick()方法。
并尝试此代码。您似乎传递了错误的参数名称
commandUP.Parameters.Add(新的SqlParameter(“@name”,Request.Cookies[“username”].Value));
Add(新的SqlParameter(“@cNo”,tbcNo.Text));
Add(新的SqlParameter(“@flavor”,“香草”);
Add(新的SqlParameter(“@size”,“12'dios”) 您是否尝试过调试onclick方法?它会开火吗?此外,插入数据也不需要读取器。更改SqlDataReader readerProfile=commandUP.ExecuteReader();到commandUP.ExecuteNonQuery();谢谢你的帮助。我的onclick方法没有问题。当我禁用OnClientClick时,它可以正常工作。并非所有javascript函数都返回任何值。因此,如果您的值在那里,OnClientClick为null,并且它不起作用。然而,要执行OnClick方法,您必须获得真值。如果要继续,我的javascript将进行验证。如果是,它将保持在同一页上并执行OnClick。如果否,它仍将执行onclick并重定向到其他页面。是否可能返回false并仍执行onclick方法?我的目标是验证用户是否想继续。如果用户不想继续,则重定向到另一个页面,返回true。但是,如果用户想要继续,它将返回false,因为它将取消OnClientClick并仍然运行OnClickdoes参数has@sign或no:现在在这里不重要了,它们都可以工作。而且在添加答案之前,你应该阅读对问题的评论,因为这也是有意义的。
SqlConnection conn = new SqlConnection(sConn);
String query = "Insert into orders values (@name,@cNo, @flavor, @size)";
if (rbVanilla.Checked == true && rbS1.Checked == true)
{
SqlCommand commandUP = new SqlCommand(query, conn);
commandUP.Parameters.Add(new SqlParameter("name", Request.Cookies["username"].Value));
commandUP.Parameters.Add(new SqlParameter("cNo", tbcNo.Text));
commandUP.Parameters.Add(new SqlParameter("flavor", "Vanilla"));
commandUP.Parameters.Add(new SqlParameter("size", "12'dios"));
//Page.ClientScript.RegisterStartupScript(this.GetType(), "successful", "success();", true);
conn.Open();
SqlDataReader readerProfile = commandUP.ExecuteReader();
conn.Close();
//ClientScript.RegisterStartupScript(GetType(), "success", "test();", true);
}