Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET Model-View-Controller design question

Reply
Thread Tools

ASP.NET Model-View-Controller design question

 
 
Stan
Guest
Posts: n/a
 
      07-18-2003
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


 
Reply With Quote
 
 
 
 
Lewis Wang [MSFT]
Guest
Posts: n/a
 
      07-21-2003
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('Pa geB.aspx?parameter=aaa','A
dd_window','width=154,height=188');Add_window.focu s()">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...en-us%3B810928

Microsoft Patterns Web Presentation Patterns
http://msdn.microsoft.com/architectu...3/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" <(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.148.36.131
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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
|
|
|

 
Reply With Quote
 
 
 
 
Stan
Guest
Posts: n/a
 
      07-21-2003
HttpContext.Current is what I need!

Thanks,

-Stan

"Natty Gur" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> You should keep the controller in the session tp preserve its state. you
> can use HttpContext.Current to get the current context from your
> controller.
>
>
>
> Natty Gur, CTO
> Dao2Com Ltd.
> 28th Baruch Hirsch st. Bnei-Brak
> Israel , 51114
>
> Phone Numbers:
> Office: +972-(0)3-5786668
> Fax: +972-(0)3-5703475
> Mobile: +972-(0)58-888377
>
> Know the overall picture
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class design/ design pattern question Bartholomew Simpson C++ 2 06-12-2007 08:51 PM
Class design/design pattern resources TomTom MCSD 2 10-09-2004 07:38 AM
OO design in servlet design question dave Java 5 07-17-2004 12:58 PM
Xilinx Schematic design vs VHDL code design ZackS VHDL 5 07-09-2004 07:51 AM
Looking for help/resources on Writing a nice detailed design / tech design for vb.net code SpamProof Java 3 12-01-2003 06:06 AM



Advertisments