Partial Classes question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I upgraded a 2003 solution into a Web Application Project. When I converted
one of the forms to a partial class, the page_load event isn't executing
anymore. Is there anything else I need to do in order to make a form that was
converted into a partial class to work other than right-clicking on the form
and selecting "Convert to web application"?
 
VB.NET, I would guess. If so, the handler is probably eliminated. Add this at
the end of the Page_Load line:

Handles Me.Load


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Handles Me.Load

What's the equivelant in c#? Also, maybe you can enlighten me a bit. Where
does VS create the partial class? I can only compare the functionality of the
old .net. Whan you create a control, it adds the declaration in the code
behind. When you add an event, it gets wired up in InitializeComponent. Where
does this information go to if it's not showing up in the class?

Thanks
 
I am running to dinner, but will mark this to get back to it.

Are you not seeing the code page for the page? It should be there with the
same naming scheme as the old .NET, only partial for the class. With C#, it
should autowire. I will check, just to be safe, that there are no delegate
declarations, but I looked at a C# project earlier and there were none.

Check the @ directive and make sure the file name and class name are correct
for the partial class. If the file is missing, post back and I will follow
up after dinner.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
 
I created a new file in my existing solution Test.aspx. Here is the @Page
directive:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs"
Inherits="AutoToolsX.Test" %>

Here is the code behinde partial class:

using System;
using ...

namespace AutoToolsX
{
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}

Test.aspx.designer.cs class has the textbox and the button declarations and
the aspx has the onClick event declaration (OnClick="Button1_Click").

For existing aspx classes that were "upgraded", there is no designer class.
All there is is the @page directive:

<%@ Page language="c#" Codebehind="GroupMaintenance.aspx.cs"
AutoEventWireup="false"
Inherits="AutoToolsX.Administration.GroupMaintenance" %>

Code behind:

using...

namespace AutoToolsX.Administration
{
/// <summary>
/// Summary description for GroupMaintenance.
/// </summary>
public class GroupMaintenance : BaseForm
{
protected System.Web.UI.WebControls.Button Submit;
protected System.Web.UI.WebControls.Button Cancel;

and
private void InitializeComponent()
{
this.Submit.Click += new System.EventHandler(this.Submit_Click);
this.Cancel.Click += new System.EventHandler(this.Cancel_Click);
this.Load += new System.EventHandler(this.Page_Load);
}

The problem is that adding new controls to existing forms doesn't create a
designer class or add the required declarations in the code behind(you have
to do it manually)

So, from what I gather, for new pages, things should work as the test page
above, but for existing pages, developers would be a bit confused at first
until they are used to this. Luckily, we don't usually update existing pages
so I gues it's just another thing to get used to...

Thanks
 
Sorry for letting this slide.

Overall, MS has not done the best job at upgrading sites. In 2.0, it is
better than before, but better is a relative thing. In most instances, I
recreate pages and pull routines over. It is less of a hassle.

With the web applications model, you can work more like you did in 1.x. Not
sure if this is an option for what you are doing.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
 
Back
Top