MasterForms?

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

Guest

I want to create a WebForm that acts as a "template" for some of my other
forms. For instance a "List Template" that includes a GridView and buttons to
Refresh, Display, Add, Modify and Delete record, all located in the correct
place with the correct visual characteristics and the correct event handlers
already wired up and with the appropriate code already in place to
(consistantly) test for things like "you can't display that record because
someone else has deleted it".

As a Windows Application I would do this by creating a base class that
includes these characteristics and then I would inherit from it to create my
concrete forms. The base class would include some MustOverride methods that
would delegate to the derived classes to retrieve things like the required
dataset and the business rule object required to fill and update it.

I'd like to do something similar in asp. I've played around with MasterForms
and these appear to provide everything necessary from a visual perspective.
However, I can't find a way to implement event handlers in the MasterForm
that can call methods in the ContentForm. I think I will need to do this so
that when, for instance, the Refresh button is clicked, the MasterForm can
retrieve from the ContentForm the business rule object that will provide the
populated dataset. I was going to try and use inheritance in a similar way to
that used in my Windows Applications but I've just noticed that MasterForm
doesn't inherit from Page and that, I think, blows that approach out of the
water!

Any ideas?
 
I'd like to do something similar in asp. I've played around with
MasterForms and these appear to provide everything necessary from a
visual perspective. However, I can't find a way to implement event
handlers in the MasterForm that can call methods in the ContentForm. I
think I will need to do this so that when, for instance, the Refresh
button is clicked, the MasterForm can retrieve from the ContentForm
the business rule object that will provide the populated dataset. I
was going to try and use inheritance in a similar way to that used in
my Windows Applications but I've just noticed that MasterForm doesn't
inherit from Page and that, I think, blows that approach out of the
water!

Easiest way to handle such a scenario:

Create an Interface:
Define the Event
Define the EventHandler

Your refresh button will implement the event
Your object within the ContentForm will implmement the EventHandler

In code, bind the control within the ContentForm to handle the event.
 
Hi Richard,

Yes, you're right, the Master page in ASP.NET 2.0 mainly address the Visual
Inheritance (for provide a template based UI reusability...), but not the
class/interface inheritance in OOP. However, as Stan has mentioned, we can
still define some base (centralized) interfaces through custom event
handler properties in Master page class which handlers the postback events
for master page controls... Then, we can provide concrete implementation
in concrete page and register them through the custom event properies on
Master page..... e.g:

we have the Master page that have a linkbutton and push button, in the code
behind, we define two custom event handler properties which are called in
Master page's post back event handlers:

============Master page============
public partial class Tmp : System.Web.UI.MasterPage
{
public event EventHandler LB1_Click_Handler;
public event EventHandler B1_Click_Handler;


protected void Page_Load(object sender, EventArgs e)
{

}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (LB1_Click_Handler != null)
{
LB1_Click_Handler(sender, e);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (B1_Click_Handler != null)
{
B1_Click_Handler(sender, e);
}
}
===================

Then, in concrete page (which use this master page...) , we can define the
page specific event handlers and register them to the Master page's custom
event properties, like:

===========concrete page 1==========
public partial class conPage1 : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
Response.Write("<br/>Page_Init...");

Tmp tmp = Master as Tmp;

if (tmp != null)
{
Response.Write("<br/>Register handlers for master page...");

tmp.LB1_Click_Handler += new EventHandler(Concrete_LB1_Clicked);
tmp.B1_Click_Handler += new EventHandler(Concrete_B1_Clicked);
}
}

protected void Concrete_LB1_Clicked(object sender, EventArgs e)
{
Response.Write("<br/>Concrete_LB1_Clicked...");
}

protected void Concrete_B1_Clicked(object sender, EventArgs e)
{
Response.Write("<br/>Concrete_B1_Clicked...");
}
=======================

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: MasterForms?
| From: Spam Catcher <[email protected]>
| References: <[email protected]>
| Organization: Stan Kee Co.
| Message-ID: <[email protected]>
| User-Agent: Xnews/2005.10.18
| X-No-Archive: yes
| Reply-To: (e-mail address removed)
| Lines: 28
| X-Complaints-To: (e-mail address removed)
| X-Complaints-Info: Please be sure to forward a copy of ALL headers
otherwise we will be unable to process your complaint properly.
| Date: Wed, 18 Jan 2006 05:14:24 GMT
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli
ne.de!news.glorb.com!newsfeed2.easynews.com!easynews.com!easynews!easynews-l
ocal!fe09.news.easynews.com.POSTED!not-for-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:371624
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| |
| > I'd like to do something similar in asp. I've played around with
| > MasterForms and these appear to provide everything necessary from a
| > visual perspective. However, I can't find a way to implement event
| > handlers in the MasterForm that can call methods in the ContentForm. I
| > think I will need to do this so that when, for instance, the Refresh
| > button is clicked, the MasterForm can retrieve from the ContentForm
| > the business rule object that will provide the populated dataset. I
| > was going to try and use inheritance in a similar way to that used in
| > my Windows Applications but I've just noticed that MasterForm doesn't
| > inherit from Page and that, I think, blows that approach out of the
| > water!
|
| Easiest way to handle such a scenario:
|
| Create an Interface:
| Define the Event
| Define the EventHandler
|
| Your refresh button will implement the event
| Your object within the ContentForm will implmement the EventHandler
|
| In code, bind the control within the ContentForm to handle the event.
|
| --
| Stan Kee ([email protected])
|
 

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

Similar Threads


Back
Top