System.Web.UI.Page inheritance problem

D

Dan

I posted a similar post regarding problems with VS.NET
design mode. I fixed that problem (with much thanks to
this newsgroup) but now I have a second problem.

I have created a class called BasePage that inherits from
System.Web.UI.Page so that I can implement a "template"
for all pages in an app. My BasePage class is in a class
library project and there is also a web app in the same
solution that has a project reference back to the class
library.

When I create a new web form in VS.NET, I simply change
the code behind class to inherit from BasePage instead of
System.Web.UI.Page.

Everything works great in most cases: controls on the web
form render correctly and maintain thier state as they
should. The problem is that validation controls don't work
at all. It is as if they don't exist, it just skips the
validation all together. If I modify my code behind so it
doesn't inherit from BasePage, but from System.Web.UI.Page
directly, the validation works fine.

By adding a layer of inheritance, what is throwing this
off?

Is there something I need to add to my BasePage class?

Any help is greatly appreciated!

Here is the (simplified) code from my BasePage.cs:
*********************************************************
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace DDN.ClassLib.BaseClasses
{
public class BasePage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label
lblPgTitle;
public PageUtilities pgUtil = new
PageUtilities();

public string PgTitle
{
get
{
return ViewState
["PgTitle"] == null ? string.Empty : (string) ViewState
["MsgPgTitle"];
}
set
{
ViewState["PgTitle"] =
value;
lblPgTitle.Text = value;
}
}

protected override void OnInit
(System.EventArgs e)
{
BuildPage( GenerateHtmlForm() );
this.DataBind();
ddRelTasks.Attributes.Add
("onChange", "RelTask();");
base.OnInit(e);
}

private HtmlForm GenerateHtmlForm()
{
HtmlForm form = new HtmlForm();
form.ID = "Form1";
AddControlsFromDerivedPage(form);
return form;
}

private void AddControlsFromDerivedPage
(HtmlForm form)
{
int count = this.Controls.Count;
for( int i = 0; i<count; ++i )
{
System.Web.UI.Control
ctrl = this.Controls[0];
form.Controls.Add( ctrl );
this.Controls.Remove(
ctrl );
}
}
private void BuildPage( HtmlForm form )
{

this.Controls.AddAt( 0, new
LiteralControl( @"
<html>
<head>
<title>MyPage</title>
<link
rel='stylesheet' href='/def/inc_style.css' type='text/css'>
</head>
<body>"));

this.Controls.Add( form );

form.Controls.AddAt(1, new
LiteralControl( @"
<TABLE WIDTH='1000'
BORDER='1' CELLPADDING='0' CELLSPACING='0' BGCOLOR='white'
ID='Table1'>
<TBODY>
<TR>

<TD VALIGN='top'>

<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0'
CELLSPACING='0' ID='Table2' BGCOLOR='white'>

<TBODY>

<TR class=darkbackcell>

<TD VALIGN='top'>"));

lblPgTitle = new Label();
form.Controls.AddAt(8,
lblPgTitle );
form.Controls.AddAt
(form.Controls.Count, new LiteralControl( @"


</td>

</tr>

</TABLE>

</TD>

</TR>

</TABLE>

<br>

</TD>

</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<TABLE ID='Table9'><TR><TD
HEIGHT='25' COLSPAN='2' VALIGN='top'></TD></TR></TABLE>
"));

this.Controls.Add(new
LiteralControl(@"</body></html>"));
}
}
}
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top