6 Replies - 4182 Views - Last Post: 23 April 2013 - 02:46 PM Rate Topic: -----

#1 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Javascript simply not running in asp.net app after postback

Posted 22 April 2013 - 02:21 PM

Howdy folks. I've written a asp.net application that has no separate pages. I just have the page postback to itself and based on conditions I add different html, and asp.net controls onto the page. I've got three menu bars that highlight using a little bit of javascript on the page whenever someone mouses over them, but as soon as I click one of the items on the page that loads up an information sub routine none of the javascript works anymore. I've checked the page source and my jquery script reference is always before my scripts so there is no problem, and there is only one reference in the head of the page. I've gone into the source of my aspx page and written the functions in there in there own script tag and just after the
 $(document).ready 
function. I'm unable to figure this out, but if anyone has any tips that would be helpful let me know. Thank you.

This post has been edited by trevster344: 22 April 2013 - 02:22 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Javascript simply not running in asp.net app after postback

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3354
  • View blog
  • Posts: 11,359
  • Joined: 12-December 12

Re: Javascript simply not running in asp.net app after postback

Posted 22 April 2013 - 02:41 PM

Have you checked your console for error messages? If there are none then use alerts to prove that your JS code is at least running.

This post has been edited by andrewsw: 22 April 2013 - 02:42 PM

Was This Post Helpful? 1
  • +
  • -

#3 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: Javascript simply not running in asp.net app after postback

Posted 22 April 2013 - 03:35 PM

I forgot to try some error trapping rather I didn't even think about it lol. Pretty new to javascript. Anyways I threw an alert in there and it works but after I clear my panel on postback, and change the html/asp.net controls in it, the javascript doesn't run anymore. So I know it's running on all but a few of the links. Just not really sure where it could be going wrong. Javascript is in the right spot always, references are always in the right spot, the code itself works on all except a few links posting back(not sure why), and there's nothing that could be changing so drastically in the code that it should cause the javascript to stop working. Any other ideas? Oh and the try catch error statement isn't returning any errors.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3354
  • View blog
  • Posts: 11,359
  • Joined: 12-December 12

Re: Javascript simply not running in asp.net app after postback

Posted 22 April 2013 - 03:40 PM

What did your console say? There are links in my signature.
Was This Post Helpful? 1
  • +
  • -

#5 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: Javascript simply not running in asp.net app after postback

Posted 22 April 2013 - 03:46 PM

I'll get back to you on that, installing firebug, thanks for the link!
Was This Post Helpful? 0
  • +
  • -

#6 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: Javascript simply not running in asp.net app after postback

Posted 22 April 2013 - 03:54 PM

Alright I've gotten that installed, and the error showing is the following:

ReferenceError: $ is not defined
TH4500()



I think it has to do with my URL rewriting. When I rewrite my url in the asp.net application I haven't appended any sort of extension so the url comes out as test.aspx/Categories/TH4500
It triggers every time I load a category or product since they all rewrite the same way. I need to add some sort of extension I think.

My javascript is as so:

    <script type="text/javascript">

        $(document).ready(function () {

            // $("#HideOptionsDiv").click(function () {
            //     $("#OptionsMenu").slideToggle();
            // });

            try {
                $("td span.navstyle a").mouseenter(function () {
                    $(this).css("font-weight", "bold");
                    //$(this).css("background-color", "");
                });
                $("td span.navstyle a").mouseleave(function () {
                    $(this).css("font-weight", "normal");
                    //$(this).css("background-color", "white");
                });

                $(".style8").mouseenter(function () {
                    $(this).css("font-weight", "bold");
                });

                $(".style8").mouseleave(function () {
                    $(this).css("font-weight", "normal");
                    //$(this).css("background-color", "white");
                });

                $("#cartlink").mouseenter(function () {
                    $(this).css("font-weight", "bold");
                });

                $("#cartlink").mouseleave(function () {
                    $(this).css("font-weight", "normal");
                    //$(this).css("background-color", "white");
                });
            }
            catch (Err) {
                alert(Err.message);
            }

        });
    </script>


Was This Post Helpful? 0
  • +
  • -

#7 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: Javascript simply not running in asp.net app after postback

Posted 23 April 2013 - 02:46 PM

I have figured out the problem! Thank the gods I made a typo when searching for the fix on Google lol. Anyways if you add the jquery script file to your application, and then drag and drop the reference into your pages source, it will come out with a script path that works but when it comes to url rewriting, you have to place a / otherwise it'll try to search for the script in a non existent location.

So my script reference went from this and

<script src="Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>



became

<script src="/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>



this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1