Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

70-515 - Ajax Suggested Practices

$
0
0

Hi,

I am currently in the middle of studying for my 70-515 exam (Web Application Development with Microsoft.NET Framework 4). I'm at the chapter studying AJAX, and one of the suggested practices is as follows;

"Create an AJAX client control that extends an ASP.NET button with a confirmation alert window."

Now i've attempted this practice but it doesn't seem to be working. The error I am receiving when trying to run the application is "JavaScript runtime error: 'Sys' is undefined"

I have been using the book for reference when creating the bit of code below, but it still doesn't seem to be working. I was hoping you guys may be able to shed some light on where I am going wrong.

Ajax.js

///<reference name="MicrosoftAjax.js" />

Type.registerNamespace("Ajax");

Ajax.AlertBox = function (element) {
    Ajax.AlertBox.initializeBase(this, [element]);

    Ajax.AlertBox.prototype = {
        initialize: function() {
        Ajax.AlertBox.callBaseMethod(this, 'initialize');

        this._OnClickHandler = Function.createDelegate(this, this._OnClick);
        $addHandlers(this.get_element(), {'click' : this._OnClick}, this);
        },

        dispose: function() {
        $clearHandlers(this.get_element());
        Ajax.AlertBox.callBaseMethod(this, 'dispose');
        },
        _OnClick : function() {
            alert("This box has appeared because the custom button has been clicked!");

        }
        }
        }
        Ajax.AlertBox.registerClass('Ajax.AlertBox', Sys.UI.Control);

        if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

Default.aspx

<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeFile="Default.aspx.vb" Inherits="_Default" %><asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"><script language="javascript" type="text/javascript">
        var app = Sys.Application;
        app.add_init(appInit);

        function appInit(sender, args) {
            $create(Ajax.AlertBox, null, null, null, $get('MainContent_Button1'))}</script></asp:Content><asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"><asp:ScriptManager runat="server" ID="ScriptManager1"><Scripts><asp:ScriptReference Path="~/Scripts/AjaxEnabled.js" /></Scripts></asp:ScriptManager><asp:Button id="Button1" runat="server" /></asp:Content>

The line of code that this seems to be erroring out on is within the Default.aspx on the line which has var app = Sys.Application.

Any help on this is greatly appreciated as I'm pulling my hair out on this one now!

Thanks,


Viewing all articles
Browse latest Browse all 5678

Latest Images

Trending Articles



Latest Images