cannot use codebehind for user control!

N

news.microsoft.com

Getting really frustrated, I've been trying for 6 hours now! Got this very
simple web app having a main .aspx page which has a user control (added with
the Register directive) and the TemplateTop.ascx wich works 100% until I try
adding codebehind, eg;

<%@ Control Codebehind="TemplateTop.ascx.cs" Inherits="TemplateTop" %>

And in the TemplateTop.ascx.cs file:

using ...
public class TemplateTopCB : UserControl
{
public Literal MyLiteral1;
void Page_Load(object sender, System.EventArgs e)
{
MyLiteral1.Text = "success!";
}
}


The error is:
Parser Error Message: Could not load type 'TemplateTopCB'.
 
N

news.microsoft.com

sorry my mistake, it is Inherits="TemplateTopCB" in the code - so this is
not the cause of the error!
 
N

news.microsoft.com

thought I'd let you know it's 100% working after I added
Src="TemplateTop.ascx.cs"

to the @Control directive

This puzzles me though. It tells me that the Codebehind code has to be
precompiled by Visual Web Developer to work. What if I was for instance
using a text editor to do this web, would it then be impossible without
precompiling the .cs code in command-line?!
 
D

Daves

what on earth is going on?! It works for a few times and then suddenly
(without having changed anything!!) - it is if like .Net just loves creating
errors for me!!!

The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: The system cannot find
the file specified.
Assembly Load Trace: The following information can be helpful to determine
why the assembly 'lslh5c-x, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' could not be loaded.
 
G

Guest

I usually don't use the register directive directly. I'd remove it and drag
the control onto your form via the IDE, which does that for you. I presume
this is the same for C# as it is VB. Have fun.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top