C# c语言中的条件确认框#
如何从c#调用条件确认框 我有2个隐藏字段,根据我想要调用确认框的条件 之后,我还想知道用户按下了什么(单击是或否) 设计:-C# c语言中的条件确认框#,c#,jquery,confirm,C#,Jquery,Confirm,如何从c#调用条件确认框 我有2个隐藏字段,根据我想要调用确认框的条件 之后,我还想知道用户按下了什么(单击是或否) 设计:- <input type="submit" id="btnAddPaymentMethod" onserverclick="AddPaymentMethod_Click" runat="server" value="add payment method" /> 我尝试了以下jQuery代码:- function Confirm(msg) {
<input type="submit" id="btnAddPaymentMethod" onserverclick="AddPaymentMethod_Click" runat="server" value="add payment method" />
我尝试了以下jQuery代码:-
function Confirm(msg) {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm(msg)) {
confirm_value.value = "Yes";
$('#btnAddPaymentMethod').click();
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
我没有运行你的代码。但是,当您为输入控件设置了
runat=“server”
时,它将附加asp.net唯一Id。因此,请尝试按输入控件的名称(以btnAddPaymentMethod
结尾)访问该输入控件,如下所示
更改为
$('#btnAddPaymentMethod')。单击()
到$('[id$=btnAddPaymentMethod]')。单击()代码>此jQuery代码将打开一个确认对话框,其中包含“确定”和“取消”按钮
在这里,一个id为MyConfigrmPageLink的锚定标记在单击时将请求确认。如果单击“确定”,它将前进到目标,如果单击“取消”,它将保持在同一页面上
$("a#myConfirmPageLink").click(function(){
return confirm("Are you sure you want to go to that page/site ?");
});
出于您的目的,这应该很容易修改。为什么不在javascript/jquery中设置条件,以便您可以直接调用确认而不是服务器端代码。请尝试此链接@Sunny Singh我看过那篇文章@jose,但我没有得到任何确认框,它总是显示“您单击了否!”。。
protected void Next_Click(object sender, EventArgs e)
{
if (hdnDefault.Value == hdnPrimary.Value) {
return;
} else {
//open confirm box
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "Confirm('Do you want to save new default payment method?');", true);
}
}
protected void AddPaymentMethod_Click(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes") {
ScriptManager.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
} else {
ScriptManager.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
}
}
function Confirm(msg) {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
confirm_value.value = confirm(msg)? "Yes" : "No";
document.forms[0].appendChild(confirm_value);
$('#btnAddPaymentMethod').click();
}
protected void Next_Click(object sender, EventArgs e)
{
if (hdnDefault.Value == hdnPrimary.Value) {
return;
} else {
//open confirm box
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "Confirm('Do you want to save new default payment method?');", true);
}
}
protected void AddPaymentMethod_Click(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes") {
ScriptManager.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
} else {
ScriptManager.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
}
}
function Confirm(msg) {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
confirm_value.value = confirm(msg)? "Yes" : "No";
document.forms[0].appendChild(confirm_value);
$('#btnAddPaymentMethod').click();
}