Saturday, 14 December 2013

Show message box in asp.net code behind / Alert message in asp.net code behind

Posted on 10:10 in

Introduction:

This article is helps to how Show message box (alert) using asp.net in code behind.

Source Page (Design View):

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title> Alert message box using asp.net in code behind </title>
 </head>
<body>
<form id="form1" runat="server">
<div>
div class="Column">
<asp:Label ID="lblUserName" runat="server" Text="User Name"></asp:Label>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<span class="Mandatory">*</span></div>
<div class="Column">
<asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="txtpassword" TextMode="Password" runat="server"></asp:TextBox>
<span class="Mandatory">*</span></div>
<div class="Column" style="padding-left: 150px">
<asp:Button ID="btnLogin" runat="server" BorderColor="Aqua" OnClientClick=" btnLogin_click()"
Text="Login" /></div>
</div>
</form>
</body>
</html>

Code Behind(C#) :

private void btnLogin_click(object sender, EventArgs e)
        {
            if (txtUserName.Text == "")
            {
               ScriptManager.RegisterStartupScript(this, GetType(), "Script""alert('User Name Required')",true);
                return;
            }
            // code here some else wanted
       }
Demo :

0 comments:

Post a Comment