ASP .NET 2.0 C# AjaxPro RegisterTypeForAjax
Posted
by Dan7el
on Stack Overflow
See other posts from Stack Overflow
or by Dan7el
Published on 2010-04-26T17:31:20Z
Indexed on
2010/04/26
17:33 UTC
Read the original article
Hit count: 784
I am wondering if RegisterTypeForAjax isn't working correctly. I am getting the error noted at the end of the code block below. Sample is from here: http://www.ajaxtutorials.com/asp-net-ajax-quickstart/tutorial-introduction-to-ajax-in-asp-net-2-0-and-c/
Any ideas as to why I'm getting this error? Thanks.
ASP .NET 2.0 C#
Here is the code-behind:
using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Collections.Generic; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
using AjaxPro;
namespace WebApplication1 { public partial class Ajax_CSharp : System.Web.UI.Page { protected override void OnInit( EventArgs e ) { base.OnInit( e ); Load += new EventHandler( Page_Load ); }
protected void Page_Load( object sender, EventArgs e )
{
Utility.RegisterTypeForAjax( typeof( Ajax_CSharp ) );
}
[ AjaxMethod( HttpSessionStateRequirement.ReadWrite ) ]
public string GetData()
{
// method gets a row from the db and returns a string.
}
}
Here is the ASPX page:
<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Ajax_CSharp" %>
Untitled Page function GetData() { var response; Ajax_CSharp.GetData( GetData_CallBack ); }
function GetData_CallBack( response )
{
var response = response.value;
if ( response == "Empty" )
{
alert( "No Record Found." );
}
else if ( response == "Error" )
{
alert( "An Error Occurred in Accessing the Database !!!" );
}
else
{
var arr = response.split( "~" );
var empID = arr[0].split( "," );
var empName = arr[1].split( "," );
document.getElementById( 'dlistEmployee' ).length = 0;
for ( var i = 0; i < empID.Length; i++ )
{
var o = document.createElement( "option" );
o.value = empID[i];
o.text = empName[i];
document.getElementById( 'dlistEmployee' ).add( o );
}
}
}
function dodisplay()
{
var selIndex = document.getElementById( "dlistEmployee" ).selectedIndex;
var empName = document.getElementById( "dlistEmployee" ).options( selIndex ).text;
var empID = document.getElementById( "dlistEmployee" ).options( selIndex ).value;
document.getElementById( "lblResult" ).innerHTML = "You have selected " + empName + " (ID: " + empID + " )";
}
</script>
Run it and click on the button and I get this error:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; MS-RTC LM 8) Timestamp: Mon, 26 Apr 2010 17:22:44 UTC
Message: 'Ajax_CSharp' is undefined Line: 13 Char: 11 Code: 0 URI: http://localhost:4678/Default.aspx
© Stack Overflow or respective owner