c#中的条件确认框
Conditional confirm box in c#
如何从 C# 调用条件确认框。
我有 2 个隐藏字段,根据条件我想调用确认框。
之后我还想要用户按下了什么(点击是或否)。
设计:-
<input type="submit" id="btnAddPaymentMethod" onserverclick="AddPaymentMethod_Click" runat="server" value="add payment method" />
代码:-
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);
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
}
}
}
我试过下面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').click();
更改为 $('[id$=btnAddPaymentMethod]').click();
此 jQuery 代码将打开一个带有 'ok' 和 'cancel' 按钮的确认对话框。
这里有一个id为myConfirmPageLink的锚标签,点击后会要求确认。如果单击“确定”,它将继续到目标,如果单击“取消”,它将停留在同一页面上。
$("a#myConfirmPageLink").click(function(){
return confirm("Are you sure you want to go to that page/site ?");
});
这应该很容易根据您的目的进行修改。
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();
}
如何从 C# 调用条件确认框。
我有 2 个隐藏字段,根据条件我想调用确认框。
之后我还想要用户按下了什么(点击是或否)。
设计:-
<input type="submit" id="btnAddPaymentMethod" onserverclick="AddPaymentMethod_Click" runat="server" value="add payment method" />
代码:-
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);
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
}
}
}
我试过下面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').click();
更改为 $('[id$=btnAddPaymentMethod]').click();
此 jQuery 代码将打开一个带有 'ok' 和 'cancel' 按钮的确认对话框。
这里有一个id为myConfirmPageLink的锚标签,点击后会要求确认。如果单击“确定”,它将继续到目标,如果单击“取消”,它将停留在同一页面上。
$("a#myConfirmPageLink").click(function(){
return confirm("Are you sure you want to go to that page/site ?");
});
这应该很容易根据您的目的进行修改。
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();
}