button.attributes.add("onclick","return confirm('the message you need to show');")
我的代码是这样的: If MessageBox.Show(strMsg, strMsg,_ MessageBoxButtons.YesNo,_ MessageBoxIcon.Exclamation,_ MessageBoxDefaultButton.Button1,_ MessageBoxOptions.RightAlign) = DialogResult.Yes Then ********** ********** End If 我想以同样的方式,但是弹出的对话框是在客户端的!
If MessageBox.Show(strMsg, strMsg,_
MessageBoxButtons.YesNo,_
MessageBoxIcon.Exclamation,_
MessageBoxDefaultButton.Button1,_
MessageBoxOptions.RightAlign) = DialogResult.Yes Then
**********
**********
End If
我想以同样的方式,但是弹出的对话框是在客户端的!
在Windows程序上行的通
在Web上就不行了
给你一个例子.
在.cs代码中编写
string Action = (Request.QueryString["Action"]!=null)?Request.QueryString["Action"].ToString():"1";
if(Action=="1")
{
Response.Write("<script language=javascript>window.close();</script>");
}
if(Action=="2")
{
Server.Transfer("UILogon.aspx");
}在页面中编写
<script language="javascript">
function ComfirmExit(action){
if(action==1)
{
myconfirm = confirm("确实要关闭窗口,退出报表管理系统吗?");
if (myconfirm==true){
top.location.href="logout.aspx?Action=1";
}
}
if(action==2)
{
myconfirm = confirm("确实要注销吗?");
if (myconfirm==true){
top.location.href="logout.aspx?Action=2";
}}
}
</script><A onclick="ComfirmExit(2)" href="#" class="label" target="_self">注销</A>
<img src="./images/exit.gif"> <A onclick="ComfirmExit(1)" class="label" href="#" target="_self">
退出</A>
Response.Write("alert('数据保存成功!');");
Response.Write("</script>");
Response.Write("ans=window.confirm('新增成功! 是否回到查詢頁面 ?');");
Response.Write("if (ans==true){window.location.href='WebForm5.aspx'}</script>");
Response.Write("</script>");
using System;
using System.Text;
using System.Web; /// <summary>
/// 在Web页面上显示可包含文本和按钮(通知并指示用户)的消息框。
/// </summary>
public class WebMessageBox
{
/// <summary>
/// 显示具体消息的消息框,并执行history的回退。
/// </summary>
/// <param name="text">显示具体消息。</param>
/// <param name="pos">回退的步数。</param>
public static void Show(string text,int pos)
{
StringBuilder sb = new StringBuilder("<script language=\"javascript\">");
sb.Append("alert('").Append(text).Append("');");
sb.Append(" window.history.go(" + pos+ ");");
sb.Append("</script>"); HttpContext.Current.Response.Write(sb.ToString());
HttpContext.Current.Response.End();
}
public static void Alert(string text)
{
StringBuilder strBuilder = new StringBuilder("<script language=\"javascript\">");
if (text != String.Empty)
strBuilder.Append("alert('").Append(text).Append("');");
strBuilder.Append("</script>"); HttpContext.Current.Response.Write(strBuilder.ToString());
HttpContext.Current.Response.End();
}
}