ASP.NET Model-View-Controller design question

S

Stan

I want to make two pages interact through a controller.

1. Page A has a grid and Add button.
2. When Add button is clicked Page B pops up.
3. User enters information and clicks Save
4. Information is saved in database
5. User goes back to Page A which gets new data from database and displays
one more row.

So, the event handler for Add button on Page A might look like:

private void btnAdd_Click(object sender, System.EventArgs e)
{
Server.Transfer (string.Format ("PageB.aspx?id={0}", id));
}

but I want PageA to instantiate a controller class, which would in turn
transfer to Page B, Page B would collected data from a user and again would
called the controller to save data and controller would transfer back to the
Page A.

My problem is that I don't know where to put the controller code.

I would like the controller to be an independent class. However, if I do
that, how does the controller get reference to the current http context and
object (to do Server.Transfer for example)?

Thanks,

-Stan
 
L

Lewis Wang [MSFT]

Hi Stan,

Natty is right. The controller should be kept in session to preserve data.

I found that you need page B pops up when Add button is clicked. So, if
you want to pop up B in a new window and then the controller interact
between two windows, you can try this way:

In page A:
1.pop pop up using javascript in A:
<asp:HyperLink id="HyperLink1" style="Z-INDEX: 102; LEFT: 80px; POSITION:
absolute; TOP: 184px" runat="server"
NavigateUrl="javascript:Add_window=window.open('PageB.aspx?parameter=aaa','A
dd_window','width=154,height=188');Add_window.focus()">Add</asp:HyperLink>

2.Initial Controller in A:
Session["controller"]=new Controller();
...


In page B:
1.Add a Literal web forms control to B first, ID=Literal1

2.If you click SaveButton in B, you should save data, refresh parentwindow,
and then close B:
private void Button1_Click(object sender, System.EventArgs e)
{
//Update database using controller,
like:((Controller)Session["controller"]).save();
//Refresh parent window:
string strjscript = "<script language='javascript'>";
strjscript+="window.opener.location.reload();";
//close B
strjscript +="window.close();";
strjscript += "</script>";
Literal1.Text= strjscript;
}

In page A:
The page_load in A gets new data from database and displays one more row.


For more information, please check the following article:
HOW TO: Access ASP.NET Intrinsic Objects from .NET Components by Using
Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;810928

Microsoft Patterns Web Presentation Patterns
http://msdn.microsoft.com/architecture/patterns/03/default.aspx


HTH
Please let me know if you want more information, thanks.

Best Regards,
Lewis

This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------
| From: "Stan" <[email protected]>
| Subject: ASP.NET Model-View-Controller design question
| Date: Fri, 18 Jul 2003 17:33:23 -0400
| Lines: 32
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.148.36.131
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:160427
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I want to make two pages interact through a controller.
|
| 1. Page A has a grid and Add button.
| 2. When Add button is clicked Page B pops up.
| 3. User enters information and clicks Save
| 4. Information is saved in database
| 5. User goes back to Page A which gets new data from database and displays
| one more row.
|
| So, the event handler for Add button on Page A might look like:
|
| private void btnAdd_Click(object sender, System.EventArgs e)
| {
| Server.Transfer (string.Format ("PageB.aspx?id={0}", id));
| }
|
| but I want PageA to instantiate a controller class, which would in turn
| transfer to Page B, Page B would collected data from a user and again
would
| called the controller to save data and controller would transfer back to
the
| Page A.
|
| My problem is that I don't know where to put the controller code.
|
| I would like the controller to be an independent class. However, if I do
| that, how does the controller get reference to the current http context
and
| object (to do Server.Transfer for example)?
|
| Thanks,
|
| -Stan
|
|
|
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top