在c#中询问是否取消窗口 [英] Ask yes no cancel window in c#
问题描述
亲爱的朋友们,
我有这个ASP控件:
< asp:ImageButton id = ImageButton1 runat = server < span class =code-attribute> 工具提示 = Ver Facturas en Gracia。(Monto Bloqueado) ImageUrl = ../ Comun / Recursos / images / icons / monto_bloqueado.png < / asp:ImageButton >
我需要在c#中调用确认窗口(询问是否取消)代码背后和下一个
处理回复..
请举例说明这个
谢谢你推荐
Leonardo Ayala R.
函数ConfirmFunc(){
var retVal = confirm( 你想继续吗?);
if (retVal == true ){
alert( 用户想要继续!);
return true ;
} else {
alert( 用户不想继续!);
return false ;
}
}
< asp:imagebutton id = ImageButton1 runat = server tooltip = Ver Facturas en Gracia。(Monto Bloqueado) imageurl = ../ Comun / Recursos / images / icons / monto_bloqueado.png onclientclick = 返回ConfirmFunc(); xmlns:asp = #unknown > < / asp:imagebutton >
在按钮的点击事件上,您可以添加此代码来处理是/否回复。
DialogResult resu lt = MessageBox.Show( 你要退出吗?, 确认,messageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes){
// 做你想做的事情!!
}
else if (result == DialogResult.No){
// 做你想做的事!!
}
其他 {
// 做你想做的事情!!
}
在这个例子中我们要去询问用户他/她是否真的要清除点击按钮的输入
首先,将此脚本添加到您的代码后面
< script 类型 = text / javascript >
函数Confirm(){
var confirm_value = document。 createElement( INPUT);
confirm_value.type = hidden;
confirm_value.name = confirm_value;
if (确认( 你确定吗?你想要清除所有输入吗?)){
confirm_value。 value = 是;
} else {
confirm_value。 value = 否;
}
document.forms [ 0 ]。appendChild(confirm_value);
}
< / script >
< / script >
其次,在您的按钮上添加Confirm()类
< asp:button id = btnClear runat = server onclick = OnConfirm onclientclick = 确认()
注意重要的是指定onClick和onClientclick
第三步也是最后一步是右击你的页面并点击查看代码并添加这个功能:
public void OnConfirm( object sender,EventArgs e)
{
string confirmValue = Request.Form [ confirm_value 跨度>];
if (confirmValue == 是 )
{
// 此处的功能
}
else
{
// 此处的功能
}
}
就是这样,你很高兴!
SIDENOTE:没有取消按钮,因为它基本上具有相同的功能,没有按钮。
Dear Friends,
I have this ASP control:
<asp:ImageButton id="ImageButton1" runat="server" ToolTip="Ver Facturas en Gracia. (Monto Bloqueado)" ImageUrl="../Comun/Recursos/images/icons/monto_bloqueado.png" </asp:ImageButton>
I need to call a confirm window (ask yes no cancel) in the c# code behind and next
process the response..
Please give me an example for this
Thanks in advace
Leonardo Ayala R.
function ConfirmFunc(){ var retVal = confirm("Do you want to continue ?"); if( retVal == true ){ alert("User wants to continue!"); return true; }else{ alert("User does not want to continue!"); return false; } } <asp:imagebutton id="ImageButton1" runat="server" tooltip="Ver Facturas en Gracia. (Monto Bloqueado)" imageurl="../Comun/Recursos/images/icons/monto_bloqueado.png" onclientclick="return ConfirmFunc();" xmlns:asp="#unknown"> </asp:imagebutton>
On the click event of button you can add this code to handle the YES/NO response.
DialogResult result = MessageBox.Show("Do you want to exit?", "Confirmation", messageBoxButtons.YesNoCancel); if(result == DialogResult.Yes){ // do what you want!! } else if (result == DialogResult.No){ //do what you want!! } else{ //do what you want!! }
In this example we are going to ask the user if he/she really wants to clear the input on button click
First, add this script to your code behind
<script type="text/javascript"> function Confirm() { var confirm_value = document.createElement("INPUT"); confirm_value.type = "hidden"; confirm_value.name = "confirm_value"; if (confirm("Are you sure you want to clear all your input?")) { confirm_value.value = "Yes"; } else { confirm_value.value = "No"; } document.forms[0].appendChild(confirm_value); } </script> </script>
Second, on your button, add the Confirm() class
<asp:button id="btnClear" runat="server" onclick="OnConfirm" onclientclick="Confirm()"
NOTE IT IS IMPORTANT TO SPECIFY THE onClick and onClientclick
Third and final step is right click your page and click view code and add this function:
public void OnConfirm(object sender, EventArgs e) { string confirmValue = Request.Form["confirm_value"]; if (confirmValue == "Yes") { //your function here } else { //your function here } }
That's it, you're good to go!
SIDENOTE: There is no cancel button, since basically it has the same functionality with no button.
这篇关于在c#中询问是否取消窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!