By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

ASP.NET Model-View-Controller design question

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <no****@yahoo.com>
| 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: <Or**************@tk2msftngp13.phx.gbl>
| 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
|
|
|

Nov 17 '05 #2

P: n/a
HttpContext.Current is what I need!

Thanks,

-Stan

"Natty Gur" <na***@dao2com.com> wrote in message
news:OA**************@TK2MSFTNGP10.phx.gbl...
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!

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.