Pages

Friday 14 February 2014

How to Display Progress Bar on Button Click in Asp.net Jquery

How to Display Progress Bar on Button Click in Asp.net Jquery

.Aspx


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>jQuery show progress bar on button click asp.net</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <style type="text/css">
        .sample {
            background-color: #DC5807;
            border: 1px solid black;
            border-collapse: collapse;
            color: White;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div id="DisableDiv"></div>
        <input type="button" id="btnClick" value="Get Data" />
        <div id="testdiv"></div>
    </form>
    <script type="text/javascript"> $(function() { $('#btnClick').click(function() { $('#DisableDiv').fadeTo('slow', .6); $('#DisableDiv').append('<img src="loading.gif" style="background-color:Aqua;position:fixed; top:40%; left:46%;"/>'); setTimeout(function() { GetData() }, 1000) }) }); function GetData() { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "ShowLoadingImageonButtonClick.aspx/BindDatatable", data: "{}", dataType: "json", success: function(data) { var theHtml = data.d; $('#testdiv').html(theHtml) $('#DisableDiv').html(""); }, error: function(result) { alert("Error"); } }); } </script>
</body>
</html>



C# Code



using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;





protected void Page_Load(object sender, EventArgs e)
{
 } [WebMethod] public static string BindDatatable()
 {
GridView gv = new GridView();
 System.IO.StringWriter stringWriter = new System.IO.StringWriter();
 HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
DataTable dt = new DataTable();
 using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;
Initial Catalog=MySampleDB;Integrated Security=true"))
 {
using (SqlCommand cmd = new SqlCommand("select UserId,UserName,Location from UserInformation", con))
{
 con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
 }
 }
 gv.HeaderStyle.CssClass = "sample";
gv.DataSource = dt;
 gv.DataBind();
 gv.RenderControl(htmlWriter);
 return stringWriter.ToString();
 }


VB Code



Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.Web.UI
Imports System.Web.UI.WebControls
Partial Class VBCode Inherits
System.Web.UI.Page
Protected Sub Page_Load
(ByVal sender As Object, ByVal e As EventArgs)
End Sub <WebMethod()> _
 Public Shared Function BindDatatable() As String
 Dim gv As New GridView()
 Dim stringWriter As New System.IO.StringWriter()
Dim htmlWriter As New HtmlTextWriter(stringWriter)
Dim dt As New DataTable()
Using con As New SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true")
Using cmd As New SqlCommand("select UserId,UserName,Location from UserInformation", con)
con.Open()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
End Using
 End Using
gv.HeaderStyle.CssClass = "sample"
gv.DataSource = dt gv.DataBind()
gv.RenderControl(htmlWriter)
Return stringWriter.ToString() '
End Function
End Class








Download


No comments:

Post a Comment