473,382 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Error with code-behind for user control

Hello,

I have a set of user controls that all use the same code-behind file.
The first line of each of the ascx files looks like...

<%@ CodeFile="ShowCategory.cs" Language="C#" Inherits="ShowCategory" %>

and the top of the code-behind (ignoring the "using" statements) looks
like...

namespace MyECommClasses {
public partial class ShowCategory : UserControl {

However, when I try to run this site, VWD gives me the following error
in the code-behind file...

"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)."

As you can see, the inherits class matches the one in the class file, so
it seems that it thinks that I'm not extending the right base class.
However, one of the ones it suggests is "UserControl" which is what I do
extend.

Any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Mar 2 '06 #1
3 1159
In article <8I**************@nospamthankyou.spam>, Alan Silver
<al*********@nospam.thanx.invalid> writes
Any ideas? TIA


Well, after posting, I found the answer (as usual!!). It was the
namespace that was causing the problem. I had added that in to try and
solve an earlier problem!! Removing it fixed the error I was getting.

Unfortunately, I'm now getting a different error. The line shown
below...

ctlShowCategory = (ShowCategory)LoadControl(strControlName);

....throws an exception...

"Unable to cast object of type 'ASP.ShowCategory' to type
'ShowCategory'."

The top of the ascx file now looks like...

<%@ CodeFile="ShowCategory.cs" Language="C#" Inherits="ShowCategory"
ClassName="ShowCategory" %>

and the class definition in the code behind looks like...

public partial class ShowCategory : UserControl {

so I don't see why it can't cast it. Any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Mar 2 '06 #2
In article <X5**************@nospamthankyou.spam>, Alan Silver
<al*********@nospam.thanx.invalid> writes
Any ideas? TIA


This is getting to be a bit like a monologue!!

Anyway, I thought I would let you know that the answer turned out to be
nothing more complex than stopping the server and deleting the temporary
ASP.NET files. It seems that the server got itself confused.

Hope this helps someone.

--
Alan Silver
(anything added below this line is nothing to do with me)
Mar 2 '06 #3
Here, I find a solution.
http://msdn.microsoft.com/asp.net/re...uesasp_net.asp

Add this to your aspx Page, that consumes UserControl
<%@ Reference Control="/..<your path here>../ShowCategory .ascx" %>

Mar 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Xeon | last post by:
Hi, Is there anyway to set a custom error handler which is actually a method of a class? i.e. setting the method eh() of class foo as error handler in the snippet below. class foo { function...
2
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
17
by: Steve Jorgensen | last post by:
If you've ever employed custom error numbers and messages in you programs, you've probably ended up with code similar to what I've ended up with in the past something like... <code> public...
7
by: Steve Jorgensen | last post by:
Here is some code to generate code for raising and getting information about custom errors in an application. Executing the GenerateXyzErrDefs procedure generates the code. <tblXyzError>...
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
4
by: Eugene Anthony | last post by:
One problem with the code bellow is after this code conn.qDupUser p1,rs I added: set rs = nothing to test the error handling capability.
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.