Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

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

Posted on Wednesday, February 15, 2006 1:23 PM | Back to top


Comments on this post: Wierd problem when putting javascript functions for AJAX.NET Library in a .js file

# re: Wierd problem when putting javascript functions for AJAX.NET Library in a .js file
Requesting Gravatar...
I had this same problem....just put your include line after the </body> tag...as far as I can see, the AJAX handler adds its own code in the HEADER of your document thus throwing an exception with your included .js file
Left by Blake on Apr 10, 2006 7:26 AM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net