stupid newbie question about class declaration

S

Stephanie

Hi. I am doing a tutorial

http://www.15seconds.com/Issue/020319.htm

About creating user controls in ASP.NET. As I run through the tutorial,
there is a point after which I create a lovely looking page with text boxes
and whanot that I go into code and change

public partial class UCLogin : System.Web.UI.UserControl

to

public abstract class UCLogin : System.Web.UI.UserControl

Actually I had deleted all teh code from the code behind file and replaced
it with the tutorial. Not until I messed around with this change did I
notice it was the cause of the build error...

"Missing partial modifier on declaration of type 'UCLogin'; another partial
declaration of this type exists."

My handy dandy help file tells me that a partial class is such:

"Partial type definitions allow for the definition of a class, struct, or
interface to be split into multiple files. "

I have no interest in separating the class into separate files. When I added
a new item in VS, this partial definition was there by default. I want to
change it to abstract as the tutorial tells me to do.



Can someone please help me understand this build error and how to correct it
without specifying a partial class which I don't want? Thanks!

I hope this is not an overly ignorant question.

Thanks.

Stephanie
 
S

Stephanie

Peter said:
[...]
I have no interest in separating the class into separate files. When
I added
a new item in VS, this partial definition was there by default. I
want to change it to abstract as the tutorial tells me to do.

Can someone please help me understand this build error and how to
correct it
without specifying a partial class which I don't want? Thanks!

When you added the UserControl sub-class UCLogin to your project, VS
added a special .cs containing the Designer-generated code for the
class. You should find it under the main item for your control in
the Solution Explorer (it should have the word "Designer" in the file
name).


I am not seeing it. I started over. Steps:
- Delete all previous projects and files related to former attempts to do
this tutorial (I am really anal)
- Open Visual Studio 2008
- I observe default.aspx and default.aspx.cs and web config in my project
and in the websites folder where the stuff is stored.
- Right click on project and select Add New Item. Select Web User Control.
Name it UCLogin.
- Observe the addition of the files ICLogin.ascx and UCLogin.ascs.asp. I see
no other added file in the project or in the windows folder in which the
files are stored.

I did a search on my project for all instances of the text. I found two
instances

This code in the UCLogin.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UCLogin.ascx.cs"
Inherits="UCLogin" %>

And this code in the UCLogin.ascx.cs
public partial class UCLogin : System.Web.UI.UserControl

I leave the partial class as it is created. Build project. Lovely.
I change to the word abstract and receive the error.

When I looked in the help file, the very first thing I thought was perhaps
visual studio did something lovely for me and sought other partial class
declarations. I find none.


If you really want to start from scratch, you'll need to delete that
file from your project. Note that should you do so, you won't be
able to modify your UserControl sub-class using the Designer. But if
you're changing it to abstract, I don't think you'd be able to do
that anyway, so that shouldn't matter. :)


I don't see from the way the tutorial uses the class why it is important for
it to *be* abstract. But I am not overly worried about that at this point.
Or my ability to use the designer or lack thereof. At this point, I see this
as a nice opportunity to understand what the heck is going on. So I would
love to identify the nature of the problem.

I've done very little ASP.NET so I didn't even bother to look closely
at the tutorial you're following. But it looks to me as though
perhaps it was written a while ago, before partial classes were
supported (i.e. VS 2003 era). That may explain the disconnect
between the tutorial and what wound up happening in the IDE as you
followed it.


Which gives me a great opportunity to learn. The tutorial is irrelevant at
this point because I can reproduce the issue with the simple steps laid out
above.

Do you have any further sage wisdome to offer? Thanks for your help thus
far!
 
B

Ben Voigt [C++ MVP]

I am not seeing it. I started over. Steps:
- Delete all previous projects and files related to former attempts
to do this tutorial (I am really anal)
- Open Visual Studio 2008
- I observe default.aspx and default.aspx.cs and web config in my
project and in the websites folder where the stuff is stored.

ASP.NET doesn't create the other half of your class until it processes the
..aspx file at web application startup, that's why you can't find it.

You can however try using BOTH abstract and partial at the same time, that
way you can declare some abstract members.
 
S

Stephanie

Ben said:
ASP.NET doesn't create the other half of your class until it
processes the .aspx file at web application startup, that's why you
can't find it.
You can however try using BOTH abstract and partial at the same time,
that way you can declare some abstract members.

Thanks.
 

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

Top