jqueryexceptionasp.net-4.0master-pagesvsdoc

How to use jQuery in ASP.NET 4 master pages


I have an ASP.NET 4 web app. I am using a Master Page Site.Master. The head of the master page is:

<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js">
</script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4-vsdoc.js">
</script>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>

Currently in the content page, I have:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<% if (false)
   { %>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script>
<% } %>
<script type="text/javascript">
    $(document).ready(function () {
        alert("Welcome jQuery !");
    });
</script>
<script type="text/javascript">
function Blam() { alert("Welcome jQuery !"); }; </script>

My content Page must show an alert when a button "ViewButton" is pressed! i,e, the ViewButton must call function Blam! How do I do that??

If I run this code, I get an exception:

readyBound is not defined!

The exception is in file: jquery-1.4.4-vsdoc.js The call stack is: bindReady JScript ready JScript JScript global code JScript


Solution

  • Don't include jquery-1.4.4-vsdoc.js in your actual site; it is not meant to be functional.

    Visual Studio should automatically read that the vsdoc when you include jquery-1.4.4.js.
    Alternatively, you can include the vsdoc inside an if (false).