Link to home
Start Free TrialLog in
Avatar of tjheroff
tjheroff

asked on

CodeBehind - Inheritance - Could not load type 'HtmlControls.Form' book example

Hello I am trying to learn ASP.NET using VB.NET from a book called Visual Basic .NET Developer's Guide to ASP.NET, XML, and ADO.NET.  All the examples use this syntax so I believe they have to work.

Here is the error I receive when the page loads into Internet Explorer:

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'HtmlControls.Button'.
Source Error:
Line 1:  <%@ Page Language="VB" AutoEventWireup="false" CodeBehind="Button.aspx.vb" Inherits="HtmlControls.Button"%>
Line 2:  <!DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN">
Line 3:  <HTML>
Source File: c:\inetpub\wwwroot\button.aspx    Line: 1
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

Here is the code for the button.aspx file:
<%@ Page Language="VB" AutoEventWireup="false" CodeBehind="Button.aspx.vb" Inherits="HtmlControls.Button"%>
<!DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<Title>HtmlButton Class </Title>
</HEAD>
<Body>
<Form id="Form1" method="post" runat="server">
<button id="btnClick" title="" type="Button" runat="server">
Click Me</button>
</Form>
</Body>
</HTML>

Here is the code for the  button.aspx.vb file:
Public Class Button
Inherits System.Web.UI.Page
Protected WithEvents btnClick As System.Web.UI.HtmlControls.HtmlButton
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnClick.InnerText = "Click Me"
End Sub

Private Sub btnClick_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClick.ServerClick
Response.Write("You clicked me!")
End Sub
End Class
Avatar of laotzi2000
laotzi2000

You should compile button.aspx.vb, and you'll get a dll
copy that dll under directory c:\inetpub\wwwroot\bin
ASKER CERTIFIED SOLUTION
Avatar of imperial_p79
imperial_p79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what is ur project name .. or the namespace given to ur project .. check for it in the menu project->project properties .. in the wondow opened what is the value for the textbox "Root namespace" is it HTMLControls ... Did u compile ur project? i.e. menu .. Build->Build solution ...

by the way, all the names u have used are reserved words and its always better to avoid them . .HTMLControls, Button etc are also used by ASP.net for its own references to controls ...
hi
 your code is running perfectly in my machine , only change is namespace name in Inherits="testAppVB.Button attribute of
<%@ Page Language="VB" AutoEventWireup="false" CodeBehind="Button.aspx.vb" Inherits="HtmlControls.Button"%>

make sure that HtmlControls is your namespace name
rashmitodkar, seems like u landed to the same conclusion that i have already asked tjheroff to check :-)
:) i think we two are writting our comments at the same tip of time . becoz when i opened this page it did not have your comment :)
Avatar of tjheroff

ASKER

Removing the "inherits" worked.   Thanks!
am suprised how removing the inherits would work .. did the code-behind code also execute properly after removing the inherits statement? Could you please explain?

This is what MSDN says about those attributes in the page directive (@Page ..)
The Codebehind, Inherits, and Src Attributes
In Web Forms that use code-behind files, the @ Page directive (or @ Control in user control files) contains attributes that specify the relationship of the .aspx file and its code-behind file. These attribute are:

Codebehind   In Visual Studio, this attribute references the name of a file that contains the class for the page. For example, if you create a Web Forms page in Visual Studio called WebForm1, the Codebehind attribute will point to WebForm1.aspx.vb or WebForm1.aspx.cs. This attribute is used only by the Visual Studio Web Forms Designer. It tells the designer where to find the page class so that the designer can create an instance of it for you to work with. The attribute is not used at run time.
******************************
Inherits   Identifies the class from which the page derives. In Visual Studio, this points to a class in the project assembly (.dll), as shown in the diagram above.
************************
So how does ur code work??? i.e. if u have code in the .vb file
Rejojohny - thank you for the follow up question.  But, I am unable to answer the question.  I am new to ASP.NET and VB.NET and am trying to understand what is going on as well - this is an example in the book I mentioned and that I couldn't get it to work.  I am hoping that as I get through the book I will "get it".