J.Olsson J.Olsson - 1 year ago 91
Javascript Question

'Sys' is undefined - Ajax - master and contentpages ASP.NET 4.0

I've been having this problem for quite a while now and tried various solutions, Editing the Webconfig with various tags.

Im using Updatepanels, timers and AJAX on my webpage.(can it be AJAX that throws the error?)

I really dont know how to define the problem, becuase i really dont know where to trace it.

I've placed a onload on the body in the masterpage (dont know if thats right)
Heres some markup code and my Javascript code that i think throws the error.


<!DOCTYPE html>
<html lang="en">
<head runat="server">
<meta charset="utf-8" />
<title><%: Page.Title %> - </title>
<link href="~/Content/Site.css" rel="stylesheet" />
<link href="~/Content/BarChart.css" rel="stylesheet" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<asp:PlaceHolder runat="server">
<script src="<%: ResolveUrl("~/Scripts/_references.js") %>"></script>
<script src="<%: ResolveUrl("~/Scripts/modernizr-2.5.3.js") %>"></script>
<script src="<%: ResolveUrl("~/Scripts/jquery-1.7.1.js") %>"></script>
<script src="<%: ResolveUrl("~/Scripts/jquery-1.7.1.min.js") %>"></script>
<script src="<%: ResolveUrl("~/Scripts/jquery-ui-1.8.20.js") %>"></script>
<script src="<%: ResolveUrl("~/Scripts/jquery-ui-1.8.20.min.js") %>"></script>
<script src="<%: ResolveUrl("~/Scripts/ButtonManager.js") %>"></script>
<script src="<%: ResolveUrl("~/Scripts/BarChart.js") %>"></script>
<meta name="viewport" content="width=device-width" />
<asp:ContentPlaceHolder runat="server" ID="HeadContent" />
<body >
<form runat="server">
<asp:ScriptManager runat="server">
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="jquery.ui.combined" />
<div class="content-wrapper">
<div class="float-left">
<asp:ImageButton ID="Logo" cssclass="site-title" runat="server" PostBackUrl="~/" ImageUrl="~/Images/Logo.png" />
<div class="float-right">
<section id="login">
<asp:LoginView runat="server" ViewStateMode="Disabled">
<li><a id="registerLink" runat="server" href="~/Account/Register.aspx">Register</a></li>
<li><a id="loginLink" runat="server" href="~/Account/Login.aspx">Log in</a></li>
Hello, <a runat="server" class="username" href="~/Account/Manage.aspx" title="Manage your account">
<asp:LoginName runat="server" CssClass="username" />
<asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" />
<ul id="menu">
<li><a runat="server" href="~/">Home</a></li>
<li><a runat="server" href="~/Barchart.aspx">About</a></li>
<li><a runat="server" href="~/Contact.aspx">Contact</a></li>
<div id="body">
<asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
<section class="content-wrapper main-content clear-fix">
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
<div class="content-wrapper">
<div class="float-left">
<p>&copy; <%: DateTime.Now.Year %> - My ASP.NET Application</p>


<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
<asp:Content runat="server" ID="BodyContentHome" ContentPlaceHolderID="MainContent" >
<asp:Panel ID="UpdatepanelWrapper" CssClass="Updatepanelwrapper" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<asp:PlaceHolder runat="server" ID="WholeWrapper">

<asp:PlaceHolder runat="server" ID="QuestionWrapper">
<asp:PlaceHolder runat="server" ID="LabelQuestion"></asp:PlaceHolder>
<asp:PlaceHolder runat="server" ID="Question"></asp:PlaceHolder>
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnDelete" EventName="Click" />

<asp:Panel ID="ButtonPanel" CssClass="ButtonPanel" runat="server">
<asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/Images/Deleteicon.png" CssClass="DeleteButtonHidden" OnClientClick="btnDelete_Click" />
<asp:ImageButton ID="btnAdd" runat="server" ImageUrl="~/Images/Addicon.png" CssClass="AddButtonMoreMargin" OnClientClick="btnAddQuestion_Click" />
<asp:Button ID="btnSendQuestions" runat="server" Text="Skapa Föreläsning och frågor" OnClick="btnSendQuestions_Click" ValidationGroup="QuestionGroup" />



if (window.addEventListener) window.addEventListener("load", load(), true);
else window.onload = load();

function load() {

function EndRequestHandler(sender, args) {

Answer Source

I just solved the problem. I think. I knew the function was run before the DOM was build.

So i just did this

$(document).ready(function () {

One problem yet presists. When i clicking on the Imagebutton btnAdd The console says:

Uncaught ReferenceError: btnAddQuestion_Click is not defined

this directs me to my code line where this ImageButton is written.

Internet Explorer doesn't like this at all. but other browsers just proceed like it was nothing, even if the error message appears in the Dev-Console.

The Button functionality works to. the only problem is the error.

EDIT: This is now Solved. i was using "OnClientClick". on the ImageButtons. I changed it to OnClick and that solved this issue. I dont know the difference between theese two, but im happy as long as it works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download