problem extending a webcontrol

S

SoftLion

Hi,
I've created a default asp.net web page and dragged a DataGrid inside it.
I would like to create a simple custom class derived from DataGrid to hide
all relevant code in it, instead of putting the code (especially for the
events) in the _default class.

This class is called DGMGrid2. I replaced the declaration :
protected System.Web.UI.WebControls.DataGrid DataGrid1;
with
protected DGMGrid2 DataGrid1;

public class DGMGrid2 : System.Web.UI.WebControls.DataGrid
{
public void DMGrid2() {}
}

That should work ?
It compiles OK but when executed there is a parse error:

Parser Error Message: The base class includes the field 'DataGrid1', but its
type (Foo.DGMGrid2) is not compatible with the type of control
(System.Web.UI.WebControls.DataGrid).
Error:
Line 20: <ASP:DATAGRID enableviewstate="false" id="DataGrid1"
runat="server" showfooter="False" width="100" cellpadding="2" pagesize="100"
autogeneratecolumns="False" horizontalalign="Center">

What is the right way to do that ?
Thanks !!
 
J

John Saunders

SoftLion said:
Hi,
I've created a default asp.net web page and dragged a DataGrid inside it.
I would like to create a simple custom class derived from DataGrid to hide
all relevant code in it, instead of putting the code (especially for the
events) in the _default class.

This class is called DGMGrid2. I replaced the declaration :
protected System.Web.UI.WebControls.DataGrid DataGrid1;
with
protected DGMGrid2 DataGrid1;

public class DGMGrid2 : System.Web.UI.WebControls.DataGrid
{
public void DMGrid2() {}
}

That should work ?
It compiles OK but when executed there is a parse error:

Parser Error Message: The base class includes the field 'DataGrid1', but its
type (Foo.DGMGrid2) is not compatible with the type of control
(System.Web.UI.WebControls.DataGrid).
Error:
Line 20: <ASP:DATAGRID enableviewstate="false" id="DataGrid1"
runat="server" showfooter="False" width="100" cellpadding="2" pagesize="100"
autogeneratecolumns="False" horizontalalign="Center">

What is the right way to do that ?

Your .aspx page is referencing an ASP.NET DataGrid (type
System.Web.UI.WebControls.DataGrid), but you are actually using a DGMGrid2.
You should register your DGMGrid2 class (as "mine", for instance), then
reference "<mine:DMGrid2 ... />" in the .aspx page.

Also, remove the empty constructor. You don't want a return type in a
constructor, and the system-supplied default constructor will do the same
thing anyway.
 
S

SoftLion

Your .aspx page is referencing an ASP.NET DataGrid (type
System.Web.UI.WebControls.DataGrid), but you are actually using a DGMGrid2.
You should register your DGMGrid2 class (as "mine", for instance), then
reference "<mine:DMGrid2 ... />" in the .aspx page.

Ok here is my new class:
public class DGMGrid2 : System.Web.UI.WebControls.DataGrid
{
}

And here is the Register directive:
<%@ Register TagPrefix="LocalGrid" Namespace="MyMainPage"
assembly="MyMainPage" %>

And here is the replacement tag :
<LocalGrid:DMGrid2 .... />

New error:
Could not load type MyMainPage.DMGrid2 from assembly MyMainPage,
Version=1.0.1627.25616, Culture=neutral, PublicKeyToken=null.

I don't want to create a nwe file for this class, nor a new special
assembly. I want to use the current page file. Any simple way to do this ?

Thks!
 
J

John Saunders

SoftLion said:
Ok here is my new class:
public class DGMGrid2 : System.Web.UI.WebControls.DataGrid
{
}

And here is the Register directive:
<%@ Register TagPrefix="LocalGrid" Namespace="MyMainPage"
assembly="MyMainPage" %>

And here is the replacement tag :
<LocalGrid:DMGrid2 .... />

New error:
Could not load type MyMainPage.DMGrid2 from assembly MyMainPage,
Version=1.0.1627.25616, Culture=neutral, PublicKeyToken=null.

I don't want to create a nwe file for this class, nor a new special
assembly. I want to use the current page file. Any simple way to do this ?

Is your application called "MyMainPage"? If not, then that's not the right
name for the assembly. You need to specify the <appname>.dll file in your
bin folder.
 
S

SoftLion

Is your application called "MyMainPage"? If not, then that's not the right
name for the assembly. You need to specify the <appname>.dll file in your
bin folder.

yes it is.
It appears there is no way to do this simply,
WebForms are just not as easy as MFC, ATL or WinForms.

B.
 
J

John Saunders

SoftLion said:
yes it is.
It appears there is no way to do this simply,
WebForms are just not as easy as MFC, ATL or WinForms.

Ok, so you're saying there's a MyMainPage.dll in your bin directory?
 

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