![](/img/trans.png)
[英]Block an asp:Button OnClick event in C# from the OnClientClick event in JavaScript?
[英]call OnClientClick and Onclick together in c# Button Event
我有一個Asp.Net c#應用程序,其中在mAsterpage上具有“注銷”按鈕。
我正在嘗試單擊“注銷”來提醒確認窗口。 如果選擇“是”,則將其重定向到“登錄頁面”。
所以我在下面嘗試過。 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>
在按鈕上,單擊我已寫以下代碼。
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
{
}
}
我收到一個錯誤,無法評估表達式,代碼在以下行中優化。...錯誤。 並且頁面沒有被重定向到所需頁面。
Response.Redirect(ConfigurationManager.AppSettings["LogoutURL"].ToString());
任何人都可以提出建議,我如何實現這一目標。
此確認框可幫助您獲得有關Ajax的正確響應。
用於獲取確認值的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>
在C#上獲取執行數據的代碼。
string confirmValue = Request.Form["confirm_value"];
string[] Value_Confirm = confirmValue.Split(',');
if (Value_Confirm[Value_Confirm.Length-1] == "Yes")
{}
或在此處查看: http : //www.codeproject.com/Answers/1070495/Ask-yes-no-cancel-window-in-csharp#answer6
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.