Below is the code of a simple page with a button.
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true"
CodeBehind="AdminPage.aspx.cs" Inherits="School.AdminPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
function calling() {
var user = "all";
alert(user)
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<button runat="server" onclick="calling()">
Mybutton</button>
</asp:Content>
On click of button, alert appear and when i click ok on that alert dialog box…page gets reloaded….why it get reloaded and how to stop this.
The “default event” is occurring.
To disable it, use return before you function call as follows:
And in the function: