Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

jQuery working slow

I have used JQuery in my page and added some libraries also. When i call jAlert on client side it works fine but when i call it on post back of page it takes a lot of time compared to calling it on client side.
0
Sudhanshum
Asked:
Sudhanshum
1 Solution
 
VijayBalkawadeCommented:
Please share some code snippets.
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
Where are you placing the script?

HTML parsing is sequential (from top to bottom) and script blocks are blocking.
This means that your code won't be parsed and executed until the HTML parser reaches there and any other scripts you might have before will delay the execution.

JavaScript is not slow and jQuery (that is nothing but JavaScript) performs very well.

Revise your code and explain us how and what exactly are you trying to do.

Cheers! :)
0
 
InsoftserviceCommented:
Please share the code as its very difficult to trace the exact issue
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
leakim971PluritechnicianCommented:
look for missing file, especially pictures.
if any, replace $(window).load by $(document).ready
0
 
SudhanshumAuthor Commented:
The code shows how i am calling the script and what jQuery files i am using.
JQUERY-Example.zip
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
I don't like to do this like this.
Instead of injecting script calls, it's much clearer to have input hidden fields that define state.

Something like this:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 runat="server">
    <title></title>

    <link href="Scripts/_assets/css/jquery.alerts.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/_assets/js/jquery.js" type="text/javascript"></script>
    <script src="Scripts/_assets/js/jquery.ui.draggable.js" type="text/javascript"></script>
    <script src="Scripts/_assets/js/jquery.alerts.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            var $hasErrors = $hasErrors('#hasErrors');
            if ($hasErrors.val() === 'true') {
                jAlert("error", "message", "Error");
            }
        });
    </script>

</head>
<body>
    <input type="hidden" value="<%= HasErrors.ToString() %>" />
    
    <form id="form1" runat="server">
    <div style="width: 865px; height: 92px; margin-bottom: 0px">
        <asp:Label ID="Lbl" runat="server" Text="UserName"></asp:Label>
        <asp:TextBox ID="txtUname" runat="server" style="margin-left:10px;"></asp:TextBox>
        <br />
        <asp:Label ID="LlblPass" runat="server" Text="Password"></asp:Label>
        <asp:TextBox ID="txtPass" runat="server" style="margin-left:15px;"></asp:TextBox>
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" style="margin-left:80px;"/>
    </div>
    </form>
</body>
</html>

Open in new window

The backend should be something like (sorry if the VB code is not fully correct):
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
        'Calling the database here and validating values.
        HasErrors = True
        'Other functionalities
    End Sub

    Dim _hasErrors As Boolean = False
    Public Property HasErrors() As Boolean
        Get
            Return _hasErrors
        End Get
        Set(ByVal value As Boolean)
            _hasErrors = value
        End Set
    End Property

End Class

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now