I was trying to gather all my JavsScript functions and
put them in a single .js file so that everything will be inorder and in one
place. Below you can see that there are 2-3 functions in my .js file.
function Foo()
{
alert('Foo has been called.');
}
function GreetUser()
{
WebForm1.GreetUser(GreetUser_CallBack);
}
function GreetUser_CallBack(response)
{
alert(response.value);
}
Now after defining the functions I register my page to use the AJAX.NET
Library.
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(WebForm1));
}
[Ajax.AjaxMethod]
public string GreetUser()
{
return "Hello World";
}
}
And
now finally the Button control which will launch the GreetUser message.
<script language="javascript" src="AjaxScript.js" />
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<input type="button" value="MyButton" onclick="GreetUser();"/>
</form>
</body>
Ohh yeah I
have already added the web.config settings and all that. Now if you run this it
will throw the exception "ajax_request is undefined". If I don't use the .js
file and simply embded the JavaScript functions into the WebForm1.aspx html code
then it will work fine.
Any
ideas?
powered by IMHO 1.3