ASP.NET Model-View-Controller design question

Discussion in 'ASP .Net' started by Stan, Jul 18, 2003.

  1. Stan

    Stan Guest

    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
     
    Stan, Jul 18, 2003
    #1
    1. Advertising

  2. 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" <>
    | 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: <>
    | 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
    |
    |
    |
     
    Lewis Wang [MSFT], Jul 21, 2003
    #2
    1. Advertising

  3. Stan

    Stan Guest

    HttpContext.Current is what I need!

    Thanks,

    -Stan

    "Natty Gur" <> wrote in message
    news:...
    > 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!
     
    Stan, Jul 21, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf Müller

    Model-View-Controller Pattern in ASP.NET

    Ralf Müller, Dec 28, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    938
    Ralf Müller
    Dec 29, 2004
  2. Griff
    Replies:
    4
    Views:
    658
    Griff
    Jan 26, 2006
  3. Replies:
    7
    Views:
    448
    Thomas Maier-Komor
    Jan 31, 2005
  4. Fritz Bosch
    Replies:
    0
    Views:
    427
    Fritz Bosch
    Sep 15, 2004
  5. Deniz Dogan

    Model-view-controller and Undo

    Deniz Dogan, Nov 12, 2006, in forum: Java
    Replies:
    0
    Views:
    408
    Deniz Dogan
    Nov 12, 2006
Loading...

Share This Page