问题描述
您好朋友,
我有一个按钮单击事件
在其中
满足一些条件后,我应该得到一个确认对话框.
当我单击该确认对话框的确定"按钮时,我想在服务器端的代码中继续进行操作.
Hi firends,
I have a button click event
in it
after satisfying some condition, I should get a confirmation dialog.
When I click "OK" button of that confirmation dialog, I want to proceed further in my code on server side.
protected void btnSelectInvioces_Click(object source, EventArgs e)
{
try
{
// some code here
...
...
if(a==b)
{
// open confirmation box
if(OK) // i click ok button of confirm box
{
// proceed further...
}
}
}
catch()
{
}
}
我尝试使用
btnSelectInvioces.Attributes.Add("javascript:window.confirm","OnClcik");
也尝试过
I tried using
btnSelectInvioces.Attributes.Add("javascript:window.confirm","OnClcik");
Also tried
string strScript = string.Empty;
strScript = "javascript:window.confirm();";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "lnkReturn", strScript, true);
但没有任何效果.
帮帮我啦,
问候,
Lok ..
But nothing worked.
Help me friends,
Regards,
Lok..
推荐答案
Response.Write("<script>alert(''Hello'')</script>");
<asp:button id="btnOk" runat="server" text="Ok" onclientclick="Confirm();" onclick="btnOk_Click" xmlns:asp="#unknown" />
<asp:hiddenfield id="hdfValue" runat="server" xmlns:asp="#unknown" />
在按钮的 OnClientClick 中调用此函数
Call this function in OnClientClick of the button
<script type="text/javascript">
function Confirm()
{
var sResult = confirm("Do you want to Proceed?");
document.getElementById("hdfValue").value = sResult;
}
</script>
在代码"页面中...
In Code page...
protected void btnOk_Click(object sender, EventArgs e)
{
// If Ok means
if(hdfValue.Value.Equals(true))
{
// Your Code
}
else
{
// Your Code
}
}
欢呼:)
Cheers :)
SomeNamespace.doConfirm = function (source, message, title) {
jConfirm(message, title, function(r) {
if (r == true) {
__doPostBack(source.id, '');
}
});
return false;
};
NB: __doPostBack
脚本函数是asp.net Web表单回发到服务器并为引发事件的控件调用特定事件处理程序的标准方式.
现在,您可以将脚本附加到页面中的按钮上.Load
NB: The __doPostBack
script function is the standard way asp.net web forms postback to the server and invoke the particular event handler for the control that raised the event.
Now, you can attach the script to your button in your page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.btnSelectInvioces.Attributes.Add("onclick", "return SomeNamespace.doConfirm(this, 'Are you sure you want to do this?', 'Prompt Title');");
}
}
现在,当您单击该按钮时,您将在客户端上看到一个确认对话框.此时没有回发.
如果单击确定",则将调用标准的btnSelectInvioces_Click事件处理程序.如果单击否",则不会发生回发
Now when you click on the button, you''ll see a confirmation dialog on the client. No postback has happened at this point.
If you click OK, then the standard btnSelectInvioces_Click event handler will be invoked. If you click No, no postback will occur
这篇关于从服务器端打开确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!