Calling another controller to do it's job at current page.

  1. #1

    Calling another controller to do it's job at current page.

    Hello everyone.

    I really enjoy my adventure with ext.net but I am simultaneously learning ASP.NET so my question might be a little wierd.
    I am coding in EXT.NET MVC
    What am I trying to achieve :
    I want to have Desktop where user can decide what modules (windows mostly) one want to use.
    Since user might want one of 100 modules, I can't imagine why I should put all direct methods to controller which manages the desktop. Thus I figured out that I can create one controller per module.
    For example: let's create a window with one button and call it WindowA.
    WindowA contains only one button and text area. After a button click I want the text area changed to "Text".
    After a click on button system goes to a method in WindowAController does this change and then goes back to desktop. And after all this User sees window with a button and text area filled with "Text".

    What problems I had :
    I tried to use "RedirectToAction", it failed because of two reasons :
    returning
    Redirect(Request.UrlReferrer.ToString());
    as shown here redirected me to my desktop's Index controller, all of modules were loaded again so field was blank.
    Getting RedirectToRoute object and using
    ExecuteResult(ControllerContext)
    did nothing.

    How to do it?
    I don't know ASP.NET very well so I might be doing something bad if so, please tell me how to approach it in different way.

    rgds
  2. #2
    Hello @Malin!

    I believe what you need is something similar to what's done in this example: MVC Examples Explorer - Events - Direct Method

    In this example, when you click a button an Ext.Net.Label is changed to have its Text reflecting the server-side calculated value.

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thank you for your answer.
    This is not really what I need. My main problem is with routeing through controllers (methods in those controllers) without loosing data stored on page. Editing text I can handle, this was just a simple example.
  4. #4
    Hello again @Malin!

    Well, in that case, seems what you need is, maybe, a deeper understanding on ASP.NET pages' life cycle. It is particularly true for WebForms but also gives a good background understanding even on MVC/Razor environment.

    That's beyond our scope in Ext.NET to provide support for but if these terms above really sound like new for you, some general lines about this would be:

    - Once you open a page, you make a server request.
    - At this point server defines variables and contents, all server-side.
    - When content is ready (or as content is becoming ready), the server outputs the page in client format (HTML, JavaScript).
    - When the server finishes serving the page, all "memory" about the just built page is lost. The process can be seen as "server build html page and dumps the text to the user over the network".

    - The user then interacts with the page using web browser
    - If the user does anything that requires a response from the server, the user -- or the page the user received -- must know how to provide information back to the server in order to build the response
    - Even with some server-side storages like session data, the user still have to specify which session (and sometimes authenticate it) is current so the server can recover the information accordingly

    A practical example of all this above would be something like this:
    - You write an Asp.NET page to write a TextArea with the 'Hello' text inside.
    - The user requests it
    - When the server is building the page, it knows exactly what is to be expected to be in the textArea (the 'Hello' text).
    - After the server provides the full page, all handles and memory is freed -- now it is up to the user to handle the page
    - The user then changes the text from 'Hello' to 'There' in the TextArea, from the web browser
    - The user then clicks a button that calls a server command
    - The server does not only not have idea on whether the user has a TextArea, nor if the user has a text 'There' in that TextArea.
    - The server can at this point, for example, return a JavaScript script that the client runs upon receiving it -- and the script can do anything, like adding a new element to the page. The server can also return a (say) JSon string that, the client would have scripts ready to handle and manipulate its contents (like populating a table with the object values).
    - Back to the client side, if the client has a 'submit' button, the server will know what's on the TextArea contents if and only if the submit form is set up so that the text area contents are actually submit to the server in the process.

    Thinking that way, if you want to keep something as you walk around on routes or actions and other links, you have some approaches to keep the data on screen:
    - keep passing the important data to rebuild the page accordingly on every server call
    - use server calls that returns content that modify the page instead of reloading it (aka use AJAX)
    - similarly to the first approach, keep a session (in server's memory or in a database also on the server, for example) but on every user request, ensure the session information is kept (there are several techniques to do so, not getting deeper on the subject) between requests to/from the server.

    To your current case, unfortunately with the information you gave it is hard to tell you what to do. If you can come up with a simplified test case where we can see how far you went with the page, maybe we could offer pinpoint (or maybe just better) advice on how to proceed with the code to achieve what you want.

    Well, I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Thank you very much. This was really helpfull!
    Now I understeand much much more ;)

Similar Threads

  1. Reload page and stay in this current page
    By kdms in forum 3.x Help
    Replies: 1
    Last Post: Mar 24, 2015, 11:39 AM
  2. GridPanel - Selection only from current Page
    By skaimschneider in forum 2.x Help
    Replies: 2
    Last Post: Jan 09, 2014, 5:51 AM
  3. How to close current tab(page)?
    By HzA in forum 1.x Help
    Replies: 7
    Last Post: Feb 21, 2013, 11:55 AM
  4. Replies: 4
    Last Post: May 12, 2010, 11:26 AM
  5. Export only exporting what is in current page
    By rthiney in forum 1.x Help
    Replies: 1
    Last Post: Oct 13, 2009, 3:32 PM

Posting Permissions