How to give alert message box using jquery in asp.net using c#

Posted by Unknown On Saturday, 5 October 2013 0 comments
Hello, in this post you can display a alert msg using jquery when the textbox is empty.
For doing this you have to do as follow.
First take one .aspx form and then give the jquery link in between head tag.
Before giving jquey you have to put your jquery file in script folder as shown in below image.

 For getting the jquery file click below link
http://blog.jquery.com/2009/02/20/jquery-1-3-2-released

Now just create a Script folder in your project and copy pate the jquery file in this folder and

give the path to script register tag you mentioned in between head tag.
Now just define the function as per define in code example as below.
After that take one textbox and one button and then onclientclick event of button call the function

as define in below example.
Example=>

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetTextBoxValue.aspx.cs" 
Inherits="GetTextBoxValue" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <title></title>
    <script src="Script/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        function btnoneclick()
        {
            if ($("input:text").val()=='')
            {
                alert('Hello how s u');
                return false;
            }
            else
                return true;

        }
</script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="bigDiv">
            <asp:TextBox ID="tb6" runat="server" Text=""/>
  <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return btnoneclick();" /> 
</div>
    </form>
</body>
</html>
Output:-

0 comments:

Post a Comment