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

Posted on 2005-03-21
Medium Priority
Last Modified: 2012-05-05
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">
<Title>HtmlButton Class </Title>
<Form id="Form1" method="post" runat="server">
<button id="btnClick" title="" type="Button" runat="server">
Click Me</button>

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
Question by:tjheroff
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
LVL 12

Expert Comment

ID: 13597982
You should compile button.aspx.vb, and you'll get a dll
copy that dll under directory c:\inetpub\wwwroot\bin

Accepted Solution

imperial_p79 earned 375 total points
ID: 13598351
one of the following 2 will make things work.

1. Change the Inherits to "HtmlControls.button" (note the small case in button)
2. Completely remove the Inherits portion.

hope this would solve the problem.

LVL 26

Expert Comment

ID: 13598639
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 ...

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Expert Comment

ID: 13598671
 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
LVL 26

Expert Comment

ID: 13598684
rashmitodkar, seems like u landed to the same conclusion that i have already asked tjheroff to check :-)

Expert Comment

ID: 13598695
:) 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 :)

Author Comment

ID: 13603935
Removing the "inherits" worked.   Thanks!
LVL 26

Expert Comment

ID: 13608902
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

Author Comment

ID: 13612061
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".

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question