如何显示没有回发的警报框? [英] How to show alert box without postback?

查看:71
本文介绍了如何显示没有回发的警报框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在警报框中显示错误消息.但是显示时会得到回发.任何人都可以在没有回发的情况下显示警报吗?

解决方案



如果您在页面中使用AJAX,则可以在所需的位置调用此代码

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "test", "alert(''welcome'');");


页面加载,

Page.ClientScript.RegisterStartupScript(typeof(Page), "MyScript", "alert(''welcome'');");


如果出现警报,应将false返回到控件.如果您不返回任何东西,它将被视为true,并且会发生回发.


您的代码应如下所示.


Javascript代码:

<script language="javascript">
        function Check() {
            //If validation failed       
            alert("Check all validation");
            return false;
            
            //If validation passed in that case return true.
        }
    </script>



标记代码:

<asp:Button ID="btnTest" runat="server" Text="Post Back Test" OnClientClick="return Check();" />


I want to show error message in alert box.but it gets postback while showing it.Can any one help to show alert without postback?

解决方案

<a href="#" onclick="javascript:alert(''hi'');">Click</a>



if you use AJAX in your page you can call this code on required places

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "test", "alert(''welcome'');");


on page load,

Page.ClientScript.RegisterStartupScript(typeof(Page), "MyScript", "alert(''welcome'');");


In case of alert you should return false to the control. If you''ll not return any thing it will be considered as true and postback will happen.


Your code should look something like this.


Javascript Code:

<script language="javascript">
        function Check() {
            //If validation failed       
            alert("Check all validation");
            return false;
            
            //If validation passed in that case return true.
        }
    </script>



Markup Code:

<asp:Button ID="btnTest" runat="server" Text="Post Back Test" OnClientClick="return Check();" />


这篇关于如何显示没有回发的警报框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆