connectseekers.com

Wednesday, 22 June 2016

Show Loading While Page Loads Using jQuery in Asp.net

6/22/2016 - By Pranav Singh 0

This article will show you how you can show loading message when user click on a button control to load the next page using jQuery in asp.net.

For this article first we will create a new ap.net application and add two pages. One for ajax and other to load. So here is the code for main page.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="WebApplication7.WebForm6" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Show Loading While Page Loads Using jQuery in Asp.net</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $(document).ajaxStart(function () {
                $("#loadingDiv").css("display", "block");
            });
            $(document).ajaxComplete(function () {
                $("#loadingDiv").css("display", "none");
            });
            $("button").click(function () {
                $("#txt").load("AjaxPageLoad.aspx");
                $("#btnClick").css("display", "none");
                return false;
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="txt">
            <h2>Let AJAX change this text</h2>
            <br /><br />
        </div>
        <button id="btnClick">Change Content</button>
        <div id="loadingDiv" style="display: none; width: 100px; height: 40px; border: 1px solid black; position: absolute; top: 50%; left: 50%; padding: 0px;">
           <b><h3>Loading..</h3></b>
        </div>
    </form>
</body>
</html>

In above code I have used jQuery to perform loading. In this I have used loading function of jquery. Now check the ajax page. Here is the code for the loading page.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxPageLoad.aspx.cs" Inherits="WebApplication7.Ajax.AjaxPageLoad" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>
    </form>
</body>
</html>

In this I have added button and label control to perform that after loading of page button event can be performed.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication7.Ajax
{
    public partial class AjaxPageLoad : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(5000);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = "You have clicked the button";
        }
    }
}

Delay has been added to show the loading for a while. Now we have done run the application to check the output.



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top