Click here to Skip to main content
15,910,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

<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');");
 
Share this answer
 
v2
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();" />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900