Good morning, I have problem with using MasterPage and jQuery. I using jQuery UI with custom Theme and I'll like set design of all buttons to design jQuery UI buttons. In MasterPage a have:
<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.10.custom.min.js" type="text/javascript"></script>
<script src="js/i18n/jquery-ui-i18n.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// destroy all dialogs
$('#dialog:ui-dialog').dialog('destroy');
// set buttons
$('input:submit, button').button();
});
</script>
On default aspx page i have one asp:Button and it's looks like jQuery UI button. But in other aspx page in directory I have some asp:TextBox and one asp:Button and I have got error: Microsoft JScript - error in run program: Property $ has Null value or isn't defined. Property isn't object of Function. And button not see like jQuery UI button. What's wrong? Thank you and have a开发者_开发技巧 nice day.
Edit: Include your scripts like this:
<script type="text/javascript" src="<%=ResolveUrl("~/js/jquery-1.4.4.min.js")%>" > </script>
Or use absolute path
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
The most likely cause is that the jQuery script has not downloaded - probably due to a bad path (as mentioned by dioslaska).
I thought I'd mention a couple of good ways to debug this and see if it is correct.
The first is to use a tool such as Fiddler (free) or the excellent HttpWatch (not free unfortunately). Both of these let you se each request coming down to the browser. If any of these scripts are failing to download, you'll see an error (with a 404 error code if they are failing to download because they cannot be found).
Alternatively, view the source of your rendered web page and find the line that corresponds to you script tag for jquery-1.4.4.min.js. Cut and paste the url from the source into a new browser window (if it is a relative path, don't forget to prepend the "http://myserver/" bit). Does this page download correctly in the browser? If not - it is almost certianly the culprit.
Once you know what isn't downloading, you can start idenitfying what is wrong with the paths, and you can fix and test them.
In this way, you can debug these sort of errors where included files (be they scripts, css, images or anything else) are not being downloaded.
My doubt is the empty head in your aspx page.
Remove this empty structure:
<asp:Content ID="cphHead" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
working solution:
HtmlGenericControl jQuery = new HtmlGenericControl("script");
jQuery.Attributes.Add("type", "text/javascript");
jQuery.Attributes.Add("src", this.ResolveClientUrl("~/js/jquery-1.5.1.min.js"));
Page.Header.Controls.Add(jQuery);
not so clean, but it's working!
精彩评论