[英]call OnClientClick and Onclick together in c# Button Event
I have a Asp.Net c# application in which, having Logout Button on mAsterpage. 我有一个Asp.Net c#应用程序,其中在mAsterpage上具有“注销”按钮。
I am trying to alert confirmation window on click of LogOut. 我正在尝试单击“注销”来提醒确认窗口。 If i choose Yes, then I will redirect it into Log-in Page. 如果选择“是”,则将其重定向到“登录页面”。
So I have tried below. 所以我在下面尝试过。 OnClient Click I called below JavaScript Function. OnClient单击“我在JavaScript函数下方调用”。
<script type = "text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to save data?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
On Button Click I have wriiten Below code. 在按钮上,单击我已写以下代码。
protected void ImgbtnLogOut_Click(object sender, ImageClickEventArgs e)
{
try
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
Session.Clear();
Session.Abandon();
Response.Redirect(ConfigurationManager.AppSettings["LogoutURL"].ToString());
//Server.Transfer(ConfigurationManager.AppSettings["LogoutURL"].ToString());
}
else
{
//Do Nothing
}
}
catch (Exception ex)
{
}
finally
{
}
}
I am getting an error Unable to evaluate Expression, The code is Optimized....error in below line. 我收到一个错误,无法评估表达式,代码在以下行中优化。...错误。 And Page is not being redirected to required page. 并且页面没有被重定向到所需页面。
Response.Redirect(ConfigurationManager.AppSettings["LogoutURL"].ToString());
can anyone please suggest, how can i achieve that. 任何人都可以提出建议,我如何实现这一目标。
This confirm box help you to get correct response with having Ajax. 此确认框可帮助您获得有关Ajax的正确响应。
java script code for geting confirm value. 用于获取确认值的Java脚本代码。
<script type="text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to proceed continue ?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
On C# Code for geting exect data. 在C#上获取执行数据的代码。
string confirmValue = Request.Form["confirm_value"];
string[] Value_Confirm = confirmValue.Split(',');
if (Value_Confirm[Value_Confirm.Length-1] == "Yes")
{}
or check here : http://www.codeproject.com/Answers/1070495/Ask-yes-no-cancel-window-in-csharp#answer6 或在此处查看: http : //www.codeproject.com/Answers/1070495/Ask-yes-no-cancel-window-in-csharp#answer6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.