ASP.NET弹出提示框几种基本方法


ASP.NET弹出提示框几种基本方法

(1) 点击页面上的按钮,弹出一个对话框提示是“确定”还是“取消”操作,我们采用在按钮中添加属性来完成:
     举例如下:
    public System.Web.UI.WebControls.Button btnDelRow;
    btnDelRow.Attributes.Add("onclick", "return confirm('确定要删吗?');");

(2) 点击页面上的按钮,弹出一个对话框提示是“确定”还是“取消”操作,选择“确定”或“取消”后跳转到相应的页面:
     举例如下:
      string strMsg, string strUrl_Yes, string strUrl_No;
      Response.Write("<Script Language='JavaScript'>if ( window.confirm('"+strMsg+"')) { window.location.href='" + strUrl_Yes +
                              "' } else {window.location.href='"+ strUrl_No +"' };</script>");

(3) 对于页面完成一个操作后,弹出一个对话框提示是否“操作成功”。
     举例如下:
    Response.Write("<script>alert('删除成功!')</script>");

(4) 对于页面完成一个操作后,弹出一个对话框提示是否“操作成功”后跳转到某一个页面。
     举例如下:
    Response.Write("<script>alert('删除成功!');window.location.href ='www.cnblogs.com'</script>");

(5)允许 ASP.NET 服务器控件在 Page 中发出客户端脚本块:
    public virtual void RegisterStartupScript(string key,string script);

    举例如下:
    if(!this.IsStartupScriptRegistered("hello"))
        this.RegisterStartupScript("hello","<script>alert('你好!')</script>");

注意: ASP.NET中弹出提示对话框有哪些实现方法?在点击按钮的时候弹出提示对话框如“添加成功”这样的,本来是这样实现的,Response.Write("<script>;</script>"); 但是在页面中使用了AJAX的UpdatePanel之后就不行了。与此同时,可能出现,布局用Css,使用来弹出网页中的提示信息Response.Write("<script language=javascript>"+"alert("*")"+"</script>");之后网页布局就乱了的情况,因此使用ClientScript.RegisterStartupScript(this.GetType(), "sorry", "<script defer>window.alert('对不起,系统登录失败!');</script>");可以解决问题哦。

另外要说的是,在asp.net站点里用 response.write("<script>alert('登陆成功!')</script>");是完全可行的,但是把代码移置到ajax站点后在updatepanel的作用下,javascript在网页登陆成功时开始报异常,,而在另外一个没有使用 updatepanel控制的aspx页中response.write(.....);则能正常弹出消息提示...   使用下面的就可以了

ScriptManager.RegisterClientScriptBlock(updImageShow, typeof(UpdatePanel), "test","alert('对不起,删除失败!');", true) ;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 ASP.NET MVC 中显示框,可以使用 JavaScript 库或插件。以下是一些可供选择的示例: 1.使用 jQuery UI 对话框: 在 View 中引用 jQuery UI 库和样式文件: ``` <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> ``` 然后在 JavaScript 文件中添加以下代码: ``` $(function() { $( "#dialog" ).dialog({ autoOpen: false, modal: true }); $( "#opener" ).click(function() { $( "#dialog" ).dialog( "open" ); }); }); ``` 在 HTML 中添加一个按钮,当点击时打开对话框: ``` <button id="opener">Show Dialog</button> <div id="dialog" title="Dialog Title"> <p>Dialog content goes here.</p> </div> ``` 2.使用 Bootstrap 模态框: 在 View 中引用 Bootstrap 库和样式文件: ``` <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> ``` 然后在 HTML 中添加以下代码: ``` <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Open Modal</button> <div id="myModal" class="modal fade" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Title</h4> </div> <div class="modal-body"> <p>Modal content goes here.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> ``` 当按钮被点击时,模态框会显示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值