asp.net web page becomes slow and after adding checkbox

Last Reply 10 days ago By PrinceG

Posted 12 days ago

 Please help after adding checkbox to my weppage it is becoming very slow and not responding please help i would like to display tick items only please help

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="GenerateBarcodes.aspx.vb" Inherits="SLISWEB2023.GenerateBarcodes" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
<style type="text/css">
    body
    {
        font-family: Arial;
        font-size: 10pt;
    }
    table
    {
        border: 1px solid #ccc;
    }
    table th
    {
        background-color: #F7F7F7;
        color: #333;
        font-weight: bold;
    }
    table th, table td
    {
        padding: 5px;
        border-color: #ccc;
    }
    .Pager span
    {
        color: #333;
        background-color: #F7F7F7;
        font-weight: bold;
        text-align: center;
        display: inline-block;
        width: 20px;
        margin-right: 3px;
        line-height: 150%;
        border: 1px solid #ccc;
    }
    .Pager a
    {
        text-align: center;
        display: inline-block;
        width: 20px;
        border: 1px solid #ccc;
        color: #fff;
        color: #333;
        margin-right: 3px;
        line-height: 150%;
        text-decoration: none;
    }
    .highlight
    {
        background-color: #FFFFAF;
    }
</style>
  

 <script src="../Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
     
    <script src="../Scripts/ASPSnippets_Pager.min.js"type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        GetCustomers(1);
    });
    $("[id*=txtSearch]").live("keyup", function () {
        GetCustomers(parseInt(1));
    });
    $(".Pager .page").live("click", function () {
        GetCustomers(parseInt($(this).attr('page')));
    });
    function SearchTerm() {
        return jQuery.trim($("[id*=txtSearch]").val());
    };
    function GetCustomers(pageIndex) {
        $.ajax({
            type: "POST",
            url: "Generatebarcodes.aspx/GetCustomers",
            data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccess,
            failure: function (response) {
                alert(response.d);
            },
            error: function (response) {
                alert(response.d);
            }
        });
    }
    var row;
    function OnSuccess(response) {
        var xmlDoc = $.parseXML(response.d);
        var xml = $(xmlDoc);
        var customers = xml.find("Customers");
        if (row == null) {
            row = $("[id*=gvCustomers] tr:last-child").clone(true);
        }
        $("[id*=gvCustomers] tr").not($("[id*=gvCustomers] tr:first-child")).remove();
        if (customers.length > 0) {
            $.each(customers, function () {
                var customer = $(this);
                $("td", row).eq(0).html($(this).find("Bookcode").text());
                $("td", row).eq(1).html($(this).find("BookName").text());
                $("td", row).eq(2).html($(this).find("Author").text());
                $("td", row).eq(3).html($(this).find("yearpublished").text());
                $("td", row).eq(4).html($(this).find("Publisher").text());
               
                $("[id*=gvCustomers]").append(row);
                row = $("[id*=gvCustomers] tr:last-child").clone(true);
            });
            var pager = xml.find("Pager");
            $(".Pager").ASPSnippets_Pager({
                ActiveCssClass: "current",
                PagerCssClass: "pager",
                PageIndex: parseInt(pager.find("PageIndex").text()),
                PageSize: parseInt(pager.find("PageSize").text()),
                RecordCount: parseInt(pager.find("RecordCount").text())
            });

            $(".BookName").each(function () {
                var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
                $(this).html($(this).text().replace(searchPattern, "<span class = 'highlight'>" + SearchTerm() + "</span>"));
            });
        } else {
            var empty_row = row.clone(true);
            $("td:first-child", empty_row).attr("colspan", $("td", row).length);
            $("td:first-child", empty_row).attr("align", "center");
            $("td:first-child", empty_row).html("No records found for the search criteria.");
            $("td", empty_row).not($("td:first-child", empty_row)).remove();
            $("[id*=gvCustomers]").append(empty_row);
        }
    };
</script>
    <script type="text/javascript">
    $(function () {
        GetCustomers(1);
    });
    $("[id*=txtSearch]").live("keyup", function () {
        GetCustomers(parseInt(1));
    });
    $(".Pager .page").live("click", function () {
        GetCustomers(parseInt($(this).attr('page')));
    });
    function SearchTerm() {
        return jQuery.trim($("[id*=txtSearch]").val());
    };
    function GetCustomers(pageIndex) {
        $.ajax({
            type: "POST",
            url: "Generatebarcodes.aspx/GetCustomers",
            data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccess,
            failure: function (response) {
                alert(response.d);
            },
            error: function (response) {
                alert(response.d);
            }
        });
    }
    var row;
    function OnSuccess(response) {
        var xmlDoc = $.parseXML(response.d);
        var xml = $(xmlDoc);
        var customers = xml.find("Customers");
        if (row == null) {
            row = $("[id*=gvCustomers] tr:last-child").clone(true);
        }
        $("[id*=gvCustomers] tr").not($("[id*=gvCustomers] tr:first-child")).remove();
        if (customers.length > 0) {
            $.each(customers, function () {
                var customer = $(this);
                $("td", row).eq(0).html($(this).find("Bookcode").text());
                $("td", row).eq(1).html($(this).find("BookName").text());
                $("td", row).eq(2).html($(this).find("Author").text());
                $("td", row).eq(3).html($(this).find("yearpublished").text());
                $("td", row).eq(4).html($(this).find("Publisher").text());
  
                $("[id*=gvCustomers]").append(row);
                row = $("[id*=gvCustomers] tr:last-child").clone(true);
            });
            var pager = xml.find("Pager");
            $(".Pager").ASPSnippets_Pager({
                ActiveCssClass: "current",
                PagerCssClass: "pager",
                PageIndex: parseInt(pager.find("PageIndex").text()),
                PageSize: parseInt(pager.find("PageSize").text()),
                RecordCount: parseInt(pager.find("RecordCount").text())
            });
 
            $(".Name").each(function () {
                var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
                $(this).html($(this).text().replace(searchPattern, "<span class = 'highlight'>" + SearchTerm() + "</span>"));
            });
        } else {
            var empty_row = row.clone(true);
            $("td:first-child", empty_row).attr("colspan", $("td", row).length);
            $("td:first-child", empty_row).attr("align", "center");
            $("td:first-child", empty_row).html("No records found for the search criteria.");
            $("td", empty_row).not($("td:first-child", empty_row)).remove();
            $("[id*=gvCustomers]").append(empty_row);
        }
    };
    $(function () {
        $("[id*=gvCustomers]").find("a").click(function () {
            var row = $(this).closest("tr");
            var customerid = row.find("td").eq(0).html();
            var name = row.find("td").eq(1).html();
            var country = row.find("td").eq(2).html();
            var Stream = row.find("td").eq(3).html();
            var Types = row.find("td").eq(7).html();
            var Program = row.find("td").eq(5).html();
            var Limit = row.find("td").eq(6).html();
            var House = row.find("td").eq(8).html();
            var Regno = row.find("td").eq(4).html();
            document.getElementById("hfId").value = customerid;
            document.getElementById("hfName").value = name;
            document.getElementById("hfCountry").value = country;
            document.getElementById("hfstream").value = Stream;
            document.getElementById("hfTypes").value = Types;
            document.getElementById("hfProgram").value = Program;
            document.getElementById("hfLimit").value = Limit;
            document.getElementById("hfHouse").value = House;
            document.getElementById("hfRegno").value = Regno;
        });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
    Search:
    <asp:TextBox ID="txtSearch" runat="server" />
    <hr />
    <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="False"  ItemStyle-Width="Auto" >
        <Columns>

            <asp:BoundField HeaderStyle-Width="150px" DataField="Bookcode" HeaderText="CallNo."
                ItemStyle-CssClass="ContactName" >
<HeaderStyle Width="150px"></HeaderStyle>

<ItemStyle CssClass="ContactName"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField HeaderStyle-Width="150px" DataField="BookName"  HeaderText="Book Name"  >
<HeaderStyle Width="150px"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField HeaderStyle-Width="150px" DataField="Author" HeaderText="Author" >
<HeaderStyle Width="150px"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField DataField="yearpublished" HeaderText="Yearpublished" />
            <asp:BoundField DataField="Publisher" HeaderText="Publisher" />

          
      
            <asp:TemplateField HeaderText="Tick Item">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>

          
      
            <asp:CommandField ShowSelectButton="True" />
        </Columns>
    </asp:GridView>
    <br />
    <div class="Pager">
    </div>
        <asp:HiddenField  ID="hfId"   runat="server"> </asp:HiddenField>
        <asp:HiddenField ID="hfName" runat="server"></asp:HiddenField >
        <asp:HiddenField ID="hfCountry" runat="server"></asp:HiddenField >
          <asp:HiddenField ID="hfstream" runat="server"></asp:HiddenField >
         <asp:HiddenField  ID="hfTypes" runat="server"></asp:HiddenField>
        <asp:HiddenField ID="hfProgram" runat="server"></asp:HiddenField >
        <asp:HiddenField  ID="hfLimit" runat="server"></asp:HiddenField>
        <asp:HiddenField  ID="hfHouse" runat="server"></asp:HiddenField>
         <asp:HiddenField  ID="hfRegno" runat="server"></asp:HiddenField>
        <asp:Label ID="Usernames" runat="server" Text="Usernames"></asp:Label>
    </form>
</body>
</html>

 

Imports System.Data
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Configuration
Public Class GenerateBarcodes
    Inherits System.Web.UI.Page
    Dim conString As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
    Private Shared PageSize As Integer = 15
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindDummyRow()
        End If
    End Sub

    Private Sub BindDummyRow()
        Dim dummy As New DataTable()
        dummy.Columns.Add("bookcode")
        dummy.Columns.Add("BookName")
        dummy.Columns.Add("Author")
        dummy.Columns.Add("Class")
        dummy.Columns.Add("YearPublished")
        dummy.Columns.Add("Publisher")
        dummy.Rows.Add()
        gvCustomers.DataSource = dummy
        gvCustomers.DataBind()
    End Sub
    <WebMethod()>
    Public Shared Function GetCustomers(searchTerm As String, pageIndex As Integer) As String
        Dim query As String = "[GetCustomers_Pager2023]"
        Dim cmd As New SqlCommand(query)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@SearchTerm", searchTerm)
        cmd.Parameters.AddWithValue("@PageIndex", pageIndex)
        cmd.Parameters.AddWithValue("@PageSize", PageSize)
        cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output
        Return GetData(cmd, pageIndex).GetXml()
    End Function

    Private Shared Function GetData(cmd As SqlCommand, pageIndex As Integer) As DataSet
        Dim strConnString As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
        Using con As New SqlConnection(strConnString)
            Using sda As New SqlDataAdapter()
                cmd.Connection = con
                sda.SelectCommand = cmd
                Using ds As New DataSet()
                    sda.Fill(ds, "Customers")
                    Dim dt As New DataTable("Pager")
                    dt.Columns.Add("PageIndex")
                    dt.Columns.Add("PageSize")
                    dt.Columns.Add("RecordCount")
                    dt.Rows.Add()
                    dt.Rows(0)("PageIndex") = pageIndex
                    dt.Rows(0)("PageSize") = PageSize
                    dt.Rows(0)("RecordCount") = cmd.Parameters("@RecordCount").Value
                    ds.Tables.Add(dt)
                    Return ds
                End Using
            End Using
        End Using
    End Function
    Private Sub gvCustomers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvCustomers.SelectedIndexChanged
        Dim account As String = hfName.Value
        Dim names As String = hfId.Value
        Dim classs As String = hfCountry.Value
        Dim streams As String = hfstream.Value
        Dim types As String = hfTypes.Value
        Dim program As String = hfProgram.Value
        Dim regno As String = hfRegno.Value
        Dim bklimit As String = hfLimit.Value
        Dim house As String = hfHouse.Value
        Dim username As String = Usernames.Text


        Using Con As New SqlConnection(conString)
            Con.Open()
            Using Com2 As New SqlCommand("update ledger Set dout= DATEDIFF(d, DueDate, GETDATE()) WHERE(category Is NULL) and account= '" & account & "'", Con)
                Using RDR2 = Com2.ExecuteReader()
                End Using
            End Using
        End Using
        Response.Redirect(String.Format("Libraryorders.aspx?account={0}&names={1}&class={2}&stream={3}&types={4}&program={5}&Regno={6}&booklimit={7}&house={8}&username={9}", account, names, classs, streams, types, program, regno, bklimit, house, username))

    End Sub

    Private Sub gvCustomers_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvCustomers.RowCommand
        If e.CommandName = "Select" Then
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim row As GridViewRow = gvCustomers.Rows(index)
            Dim account As String = hfName.Value
            Dim names As String = hfId.Value
            Dim classs As String = hfCountry.Value
            Dim streams As String = hfstream.Value
            Dim types As String = hfTypes.Value
            Dim program As String = hfProgram.Value
            Dim regno As String = hfRegno.Value
            Dim bklimit As String = hfLimit.Value
            Dim house As String = hfHouse.Value
            Dim username As String = Usernames.Text

            Session("account") = account
            Session("Names") = names
            Session("Class") = classs
            Session("Stream") = streams
            Session("types") = types
            Session("Program") = program
            Session("regno") = regno
            Session("bklimit") = bklimit
            Session("House") = house
            Session("Username") = username

            Using Con As New SqlConnection(conString)
                Con.Open()
                Using Com2 As New SqlCommand("update ledger Set dout= DATEDIFF(d, DueDate, GETDATE()) WHERE(category Is NULL) and account= '" & account & "'", Con)
                    Using RDR2 = Com2.ExecuteReader()
                    End Using
                End Using
            End Using
            Response.Redirect(String.Format("LibraryordersV2.aspx"))

        End If
    End Sub

End Class

 

CREATE PROCEDURE [dbo].[GetCustomers_Pager2023]
      @PageIndex INT = 1
      ,@PageSize INT = 20
      ,@RecordCount INT OUTPUT,
@SearchTerm nvarchar(200)
AS
BEGIN
      SET NOCOUNT ON;
      SELECT IDENTITY(INT,1,1) AS RowNumber
      ,[Bookcode]
      ,[BookName]
      ,[Author]
      ,[Class]
      ,[yearpublished]
      ,[publisher]
     
      INTO #Results
      FROM [stockkabojja]
       WHERE ([BookName] LIKE @SearchTerm  or [BookName] LIKE '%'+@SearchTerm+'%' or [BookName] LIKE '%' + @SearchTerm or [BookName] LIKE @SearchTerm + '%') OR @SearchTerm = ''
      SELECT @RecordCount = COUNT(*)
      FROM #Results
            
      SELECT * FROM #Results
      WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
      
      DROP TABLE #Results
END

 

You are viewing reply posted by: PrinceG 10 days ago.