Solved

jQuery working slow

Posted on 2014-09-23
6
226 Views
Last Modified: 2014-09-25
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
Comment
Question by:Sudhanshum
6 Comments
 
LVL 1

Expert Comment

by:VijayBalkawade
ID: 40340866
Please share some code snippets.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40340894
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
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40340923
Please share the code as its very difficult to trace the exact issue
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 82

Expert Comment

by:leakim971
ID: 40341155
look for missing file, especially pictures.
if any, replace $(window).load by $(document).ready
0
 

Author Comment

by:Sudhanshum
ID: 40341209
The code shows how i am calling the script and what jQuery files i am using.
JQUERY-Example.zip
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 40341231
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Triple line in an alert message 4 19
JSON/JQuery/AJAX Error Identification 2 22
Slush on text 2 8
CSS for Popup in ASP.NET 4 11
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question