469,954 Members | 1,835 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,954 developers. It's quick & easy.

System.Web.UI.Page inheritance problem

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>"));
}
}
}

Nov 18 '05 #1
0 1233

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Steve Jorgensen | last post: by
22 posts views Thread by Matthew Louden | last post: by
2 posts views Thread by dan | last post: by
reply views Thread by Jure Leskovec | last post: by
5 posts views Thread by Invalidlastname | last post: by
2 posts views Thread by Peter Michaux | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.