我正在開發asp.net web應用程序,因爲我需要使用服務器端是/否消息框,我搜索了所有的地方,但我有沒有找到很好的解決辦法,服務器端(後面的代碼)是否確認ASP.Net中的消息框C#
我發現只有客戶端的JavaScript是/否消息僅框,如下面的代碼
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<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>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="btnConfirm" runat="server" OnClick = "OnConfirm" Text = "Raise Confirm" OnClientClick = "Confirm()"/>
</form>
</body>
</html>
代碼背後:
public void OnConfirm(object sender, EventArgs e)
{
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);
}
}
但這個解決方案沒有幫助我,我需要完全服務器端是/無信息框在asp.net c#..我搜索&嘗試下面的代碼,但它的執行部分。
protected void btnSave_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("confirm('");
sb.Append("Hi");
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", sb.ToString());
string msg = "Do you want to save data?";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "confirm('" + msg + "')", true);
}
在上面的代碼
,當我們點擊是選項必要去,我需要 是塊/當我們單擊否選項,需要移動沒有塊。
我不知道該怎麼做.. 我想下面的代碼
protected void btnSave_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("confirm('");
sb.Append("Hi");
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", sb.ToString());
string msg = "Do you want to save data?";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "confirm('" + msg + "')", true);
string confirmValue = Request.Form["confirm"];
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);
}
}
任何機構幫助我..
除非調用JavaScript函數您用戶可以走進數據中心,登錄到您的服務器,然後單擊相應的按鈕,我不確定「服務器端」對話框如何工作。你究竟想要完成什麼? –
謝謝你的迴應,對不起,先生,它不幫我.. – Surya
「它不幫助我」 - 再次,*你想達到什麼*?僅僅因爲你*希望*這樣做並不意味着你**可以**。 –