Jump to content

problem with inherits in VB


joecool2005
 Share

Recommended Posts

Hi,I try to declare my inherits like this and I get an error.I don't know how to fix. I'm a newbie on .net .Please help!Thx
<%@ Page Language="vb" AutoEventWireup="false" 		Codebehind="default.aspx.vb" 		Inherits="net.ListArticleSortable"%>

You don't have a class called "net.ListArticleSortable" in your codebehind, so you can't inherit from it. You can only inherit from the class defined on your codebehind:ClassDefault.gifNote that the class on the codebehind inherits from System.Web.UI.Page. If you don't have that, then ASP.Net doesn't have any of the requisite information it needs to build the page, so you'll get errors.
Link to comment
Share on other sites

Thanks for your help.I still have the error."Error 4 Could not load type 'ListArticleSortable'. D:\Ufile\www\net\default.aspx 1"Here is the code for default.aspx and default.aspx.vb.default.aspx

<%@ Page Language="vb" AutoEventWireup="false" 		Codebehind="default.aspx.vb" 		Inherits="ListArticleSortable"%> ...

default.aspx.vb

Imports System.CollectionsImports System.IOPublic Class ListArticleSortable	Inherits System.Web.UI.Page	...End Class

Link to comment
Share on other sites

Thanks for your help.I still have the error."Error 4 Could not load type 'ListArticleSortable'. D:\Ufile\www\net\default.aspx 1"Here is the code for default.aspx and default.aspx.vb.default.aspx
<%@ Page Language="vb" AutoEventWireup="false" 		Codebehind="default.aspx.vb" 		Inherits="ListArticleSortable"%> ...

default.aspx.vb

Imports System.CollectionsImports System.IOPublic Class ListArticleSortable	Inherits System.Web.UI.Page	...End Class

That code works perfectly fine in .Net 2.0+. It won't work in 1.1. Upgrade to the latest .Net framework and change your website's configuration through IIS to use .Net 2.0.
Link to comment
Share on other sites

Hi,It showed me this versionVersion Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210 and it still don't workThis is the error I got

Server Error in '/net' Application.--------------------------------------------------------------------------------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 'ListArticleSortable'.Source Error: Line 1:  <%@ Page Language="vb" AutoEventWireup="false" Line 2:		  Codebehind="default.aspx.vb" Line 3:		  Inherits="ListArticleSortable"%> Source File: /net/Default.aspx	Line: 1

Link to comment
Share on other sites

Thanks for your help!This is the full code for Default.aspx and Default.aspx.vbMy problem is on the Inherits="ListArticleSortable"Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" 		Codebehind="default.aspx.vb" 		Inherits="ListArticleSortable"%><html><head><title>test</title></head><body> 		<form runat="server" id="form1">   <asp:dataGrid runat="server" id="articleList" font-name="Verdana" autogeneratecolumns="False" 		   alternatingitemstyle-backcolor="#eeeeee" headerstyle-backcolor="Navy" 		   headerstyle-forecolor="white" headerstyle-font-size="15pt" 		   headerstyle-font-bold="true" 		   allowsorting="true" onsortcommand="sortDisplay">	  <Columns>		 <asp:HyperLinkColumn datanavigateurlfield="name" datatextfield="name" 							headertext="File name" sortexpression="Filename" />		 <asp:BoundColumn datafield="LastWriteTime" headertext="Last Write Time" 							itemstyle-horizontalalign="Center" dataformatstring="{0:d}" 							sortexpression="LastWriteTime" />		 <asp:BoundColumn dataField="Length" headertext="File size" 							itemstyle-horizontalalign="Right" 							dataformatstring="{0:#,### bytes}" 							sortexpression="Length" />	  </Columns>   </asp:dataGrid></form>	  </body></html>

Default.aspx.vb

Imports System.CollectionsImports System.IOPublic Class ListArticleSortable	Inherits System.Web.UI.Page	Protected WithEvents articleList As System.Web.UI.WebControls.DataGrid#Region " Web Form Designer Generated Code "	'This call is required by the Web Form Designer.	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()	End Sub	Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) _				 Handles MyBase.Init		'CODEGEN: This method call is required by the Web Form Designer		'Do not modify it using the code editor.		InitializeComponent()	End Sub#End Region	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _				 Handles MyBase.Load		If Not Page.IsPostBack Then			BindData(CompareByOptions.FileName)		End If	End Sub	Private Sub BindData(ByVal compareMethod As CompareByOptions)		Dim dirInfo As New DirectoryInfo(Server.MapPath("D:\Ufile\www\code"))		Dim fileInfoArray() As FileInfo = dirInfo.GetFiles("*")		Array.Sort(fileInfoArray, New CompareFileInfoEntries(compareMethod))		articleList.DataSource = fileInfoArray		articleList.DataBind()	End Sub	Public Sub SortDisplay(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs)		Select Case e.SortExpression			Case "FileName"				BindData(CompareByOptions.FileName)			Case "LastWriteTime"				BindData(CompareByOptions.LastWriteTime)			Case "Length"				BindData(CompareByOptions.Length)		End Select	End SubEnd ClassPublic Enum CompareByOptions	FileName	LastWriteTime	LengthEnd EnumPublic Class CompareFileInfoEntries	Implements IComparer	Private compareBy As CompareByOptions = CompareByOptions.FileName	Public Sub New(ByVal cBy As CompareByOptions)		compareBy = cBy	End Sub	Public Overridable Overloads Function Compare(ByVal file1 As Object, ByVal file2 As Object) _				 As Integer Implements IComparer.Compare		'Convert file1 and file2 to FileInfo entries		Dim f1 As FileInfo = CType(file1, FileInfo)		Dim f2 As FileInfo = CType(file2, FileInfo)		'Compare the file names		Select Case compareBy			Case CompareByOptions.FileName				Return String.Compare(f1.Name, f2.Name)			Case CompareByOptions.LastWriteTime				Return DateTime.Compare(f1.LastWriteTime, f2.LastWriteTime)			Case CompareByOptions.Length				Return f1.Length - f2.Length		End Select	End FunctionEnd Class

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...