partial classes

P

Phil Townsend

Hello,

I have come to like just about everything in VS2005 except for the
"partial class" feature. Sometimes when I add a control to a web form,
it is not referenced in the partial class [no Intellisense]. Before
VS2005 I could simply add my own reference, now I can't. Where can I
find the other "part" of the class? Or even better, is there a way to
disable this feature?

Thanks!
 
C

Chris Dunaway

I have come to like just about everything in VS2005 except for the
"partial class" feature. Sometimes when I add a control to a web form,
it is not referenced in the partial class [no Intellisense]. Before
VS2005 I could simply add my own reference, now I can't. Where can I

Why can't you? When I add a web form to my web project, I can expand
the .aspx file by clicking the little plus sign and see the .aspx.cs
file. At the top of the Solution Explorer is a button called "Nest
related files". Does it help if you click that?
find the other "part" of the class? Or even better, is there a way to
disable this feature?

I'm not sure if there is a way to turn off partial classes, but you can
move all your code into a single file if that is what you want and then
just remove the partial declaration.

Chris
 
P

Phil Townsend

Thanks for the reply.

The problem I'm having is locating where the other "part" of the partial
class is. Where does VS put it? Thanks...
 
C

Chris Dunaway

Phil said:
Thanks for the reply.

The problem I'm having is locating where the other "part" of the partial
class is. Where does VS put it? Thanks...

Physically it should be in the same folder as the .aspx file. So for
default.aspx, there should be a file called default.aspx.cs.

But like I said, just expand the node in the Solution Explorer and you
can get right to it.
 
P

Phil Townsend

Yes, I understand what you are saying. There is an aspx.cs file coupled
with the webform. However, it is only a "partial" class file. What I
need to know is where the other "part" of the aspx.cs file is stored. In
other words, there are two parts of the "partial" class. Whare are ALL
the various parts of the class [not the web form markup]? Thanks.
 
C

Chris Dunaway

Phil said:
Yes, I understand what you are saying. There is an aspx.cs file coupled
with the webform. However, it is only a "partial" class file. What I
need to know is where the other "part" of the aspx.cs file is stored. In
other words, there are two parts of the "partial" class. Whare are ALL
the various parts of the class [not the web form markup]? Thanks.

For a web form, I don't think there *is* another part other than the
page itself. At the top of the .aspx file, you should see that the
page inherits the partial class. So that is one part of the class and
the aspx.cs file contains the other part of the class.
 
P

Phil Townsend

Let me rephrase what I am asking. Where are the definitions for the web
controls that are on the web form? Where are the event handlers defined?
They are NOT in the partial class that is visibly coupled with the
webform.
 
C

Chris Dunaway

Phil said:
Let me rephrase what I am asking. Where are the definitions for the web
controls that are on the web form? Where are the event handlers defined?
They are NOT in the partial class that is visibly coupled with the
webform.

I assume you're asking if there is an equivalent in web forms of the
Windows Forms Form.Designer.cs file where all the variables are
instantiated and the events are wired up. I don't think there is.

The handlers will be in the aspx.cs file. To test this what I did was
to drag a button onto the web form. I then double clicked it.

In the .aspx page, it added an OnClick attribute to the asp:button
element.

In the .aspx.cs file it added this method:

protected void Button1_Click(object sender, EventArgs e)
{

}

I don't see any other code. I'm not sure if the code to wire up the
event handler is generated anywhere else (i.e. Button1.OnClick +=
Button1_Click;). I don't think it is, but I may be mistaken. I'm
guessing that it is wired up by ASP.Net when the page is requested.

If there is another file somewhere, I am not aware of it. (Of course
that doesn't mean its not there!!).

Cheers,

Chris
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Phil said:
Yes, I understand what you are saying. There is an aspx.cs file coupled
with the webform. However, it is only a "partial" class file. What I
need to know is where the other "part" of the aspx.cs file is stored. In
other words, there are two parts of the "partial" class. Whare are ALL
the various parts of the class [not the web form markup]? Thanks.

The code for the design is not visible in the file list, but you can get
to it eventhough.

If you search for the name of a control in the entire solution, you will
see that it's found not only in your .cs file, but also in a
..Designer.cs file. There's where the other part of the class is.
 
C

Chris Dunaway

Göran Andersson said:
Phil said:
Yes, I understand what you are saying. There is an aspx.cs file coupled
with the webform. However, it is only a "partial" class file. What I
need to know is where the other "part" of the aspx.cs file is stored. In
other words, there are two parts of the "partial" class. Whare are ALL
the various parts of the class [not the web form markup]? Thanks.

The code for the design is not visible in the file list, but you can get
to it eventhough.

If you search for the name of a control in the entire solution, you will
see that it's found not only in your .cs file, but also in a
.Designer.cs file. There's where the other part of the class is.

In any of my VS2005 Web Sites, I can find NO instances of any file
called *.designer.cs. I don't think they exist.
 
C

captainpeeps

The *.designer.vb file only exists in windows forms projects.

In the case of web projects, the declarations for the controls hosted
on the web form are written into the HTML code for the page. There
doesn't appear to be a declaration written in the language of the
project(C# or VB) in a corresponding primary partial class definition.
I suspect the primary partial class definition is compiled on the fly
at the time of the request.

If you are simply looking for the declaration of the web control, look
in the code view of the main aspx file.

Looks something like this:

"<asp:Button ID="Button1" runat="server" Style="left: 9px; position:
absolute; top: 392px" Text="Left" Width="50px" />"
 

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