AJAX Code-Behind Class Error

Reply Forum
Forum postDaniel @ 2010-03-05 03:06:30
ReplyReply to
Hi, hopefully a very easy problem. Help is appreciated! I'm new to AJAX and C#, but fluent in ASP .NET VB.

I have MS AJAX extensions installed in Visual Web Developer 2008.

I took the very first example, which looks VERY straightforward and simple. Here's the code I used on both pages:

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 id="Head1" runat="server">
<title>Hello, world!</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="MainScriptManager" runat="server" />
<asp:UpdatePanel ID="pnlHelloWorld" runat="server">
<ContentTemplate>
<asp:Label runat="server" ID="lblHelloWorld" Text="Click the button!" />
<br /><br />
<asp:Button runat="server" ID="btnHelloWorld" OnClick="btnHelloWorld_Click" Text="Update label!" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
(exactly like the example)

And here's Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnHelloWorld_Click(object sender, EventArgs e)
{
lblHelloWorld.Text = "Hello, world - this is a fresh message from ASP.NET AJAX! The time right now is: " + DateTime.Now.ToLongTimeString();
}

}

(Code was added for the button click event in the class)

There is a red line under lblHelloWorld.Text that error says:

Error 1 The name 'lblHelloWorld' does not exist in the current context C:\Users\Daniel\Documents\Visual Studio 2008\WebSites\WebSite4Ajax\Default.aspx.cs 13 9 C:\...\WebSite4Ajax\

When the page is run, there is a runtime error that says:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message:

ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

Source Error:

Line 6: using System.Web.UI.WebControls;
Line 7:
Line 8: public partial class Default : System.Web.UI.Page
Line 9: {
Line 10:

error on line 8.

Thanks kindly for helping with this.

Daniel


Forum postWebmaster @ 2010-03-05 21:46:03
ReplyReply to
Hi Daniel,

In the first line of your markup file, you reference the class "_Default" in the Inherits attribute, but your class is actually called "Default". Change the top line to something like this instead:

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

That should at least fix one problem :)


Forum postRyan @ 2011-03-25 07:20:19
ReplyReply to
Hi there,

you can get all ur queries solved @ www.projectsdeal.com

A very good platform to showcase ur project and to get any project. happy tech surfing! :)


ps: Dont hestitate to call them. i did and it helped me incredibly!











© net-tutorials.com 2006 - 2012

MailContact net-tutorials.com