Ajax application with jscript file in VB.NET

In this application help we can be easily learn how can use ajax application with jscript file.
  • 2169

Intoroduction : The ajax application with java script classes and namespace.

Step:1 We create ajax application.

  • Open visual studio and go to file menu.
  • Select website optionand click asp.net website .
  • Default.aspx page  open.

n1.gif

n2.gif
 

Step: 2 Go to solution explorer and right click .

  • Select add new item after select jscript file and add it.
  • Now jscript file will open.
  • Write a code in jscript.
n3.gif
 

Code:

Type.registerNamespace("sachin");

sachin.car = function (strmake, strmodel, stryear) {

    this._make = strmake;

    this._model = strmodel;

    this._year = stryear;

};

sachin.car.prototype =

{

    get_make: function () {

        return this.get_make;

    },

    get_model: function () {

        return this.get_model;

    },

    get_makeandmodel: function () {

        return this._make + "" + this._model;

    },

    get_year: function () {

        return this._year;

    },

    dispose: function () {

      alert("hi");

    }

};

sachin.car.registerClass("sachin.car");

Step:3 Now again go to solution explorer and right click.

  • We select a webforms option and add click.
  • Now we go to toolbox and select a control.
  • We select a button, scriptmanger control.
n6.gif
n8.gif
 

Step:4 Go to source  and write a code.

Code :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

   <title> my ajax</title>

   <script language = "javascript" type ="text/javascript">

function Button1_onclick() {

    var car = new sachin.car('hero', 'driver', '2011');

      alert(car.get_makeandmodel());

      alert(car.get_year());

      return false;

       }

  </script>

</head>

<body>

     <form id="form1" runat="server">

    <div>

      <asp:ScriptManager ID="ScriptManager1" runat="server">

        <Scripts>

             <asp:ScriptReference Path = "~/sachin.js" />

                </Scrip>

           </asp:ScriptManager>

       </div>

     <input id="Button1" type = "button" value = "button" onclick = "return Button1_onclick()" />

</form>

</body>

</html>

Now press F5 and run the programe and find out the result. when we click in button the find as output for the ajax application
 

n9.gif

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.