Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

I have the down posted javascript code.It is working fine when the window .load is commented but does not work when it is not commented so how to solve it ?

XML
<script runat="server">

        <WebMethod()> _
        Public Shared Function Session(ByVal key As String) As String
            Return DirectCast(HttpContext.Current.Session(key), String)
        End Function

    </script>

    <script type="text/javascript">
        var cult = "";
//        $(window).load(function() {
            function pageLoad(sender, arg) {
                PageMethods.Session("Lang", OnCallComplete, OnCallError);
            }
            function OnCallComplete(result, userContext, methodName) {

                cult = result;
                var p = $("#b");
                var pos = p.position();
                var sub = document.getElementById("men");
                sub.top = pos.top + 70;
                alert(cult);
                if (cult == "en-US") {
                    sub.left = pos.left;


                }
                if (cult == "ar-LB") {

                    sub.left = pos.left - 70;
                }


                $("#men").offset({ left: sub.left, top: sub.top });
            }

            function OnCallError(error, userContext, methodName) {

                if (error !== null) {
                    alert(error.get_message());
                }
            }

//        });

    </script>
Posted

1 solution

Try this:
JavaScript
$(window).load(function() {
    PageMethods.Session("Lang", OnCallComplete, OnCallError);
}

Keep your other functions outside window.load.
 
Share this answer
 
Comments
mhamad zarif 1-Aug-11 6:35am    
tried it but still not working.I am putting alerts and they are not firing which means that the code is not running
[no name] 1-Aug-11 7:25am    
Just because it doesn't work for you, it doesn't mean that the solution is wrong. There was no need to downvote it without even asking for an explanation. Where did you put your alert in? Have you included script tags to the jQuery scripts? Are you using Ajax?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900