Server-side Render to Create Client-Side Snippets of code (Handlers)...

  1. #1

    Server-side Render to Create Client-Side Snippets of code (Handlers)...

    I know I've hinted at this before but I thought it was time to add this as it own official Feature Request. It's kind of a big request but it provides a slight paradigm shift in the way in which we programmers can write client-side code without changing how we code on the server-side (and impacts how managers can choose to hire).

    Right now, calls to X.AddScript, ctl.Render, X.MsgBox().Show, X-Render, and a hundred other various calls render client-side code to the response stream.

    But there are times when you want to write server-side code the same way you do today except you want to divert the render-stream to a listener or handler or a X.MsgBox OK button or whatever (as a string).

    For instance, lets say I want a button's click listener to Launch a MessageBox prompt on the client-side.

    Today, we write:
    Btn1.Listener.Click.Handler = "Ext.MessageBox.show({    title: 'Test',
        msg: 'This is a test',
        buttons: Ext.MessageBox.OK
    });"
    This requires an intimate knowledge of both server-side and client-side coding (which means from a manager's standpoint, I have to hire developers with expertise in both).

    To work around not knowing the client-side well enough, we can make the above click listener instead into a DirectEvent/Method and simply write server-side code exclusively:
    X.MessageBox.Alert( "Test", "This is a Test." ).Show();
    This means I can hire server-side coders again, but unfortunately, this comes at the cost of a post-back for a very simple extjs command. It's not ideal.


    Ext.Net already has the 1000 or so client-side API hookups already in place and ready to go, but yet, I cannot pass the code created by X.MessageBox.Alert( "Test", "This is a Test." ).Show(); to Btn1.Listener.Click.Handler.

    Ideally, there are a number of ways I'd love to see this work, including:
    Btn1.Listener.Click.Handler = 
        X.ClientCode( () => {
            // Any server-side code placed in here will render to client-side string
            X.MessageBox.Alert( "Test", "This is a Test." ).Show();
        } );
    or
    var Renderer = new Ext.Net.Renderer();
    using( var ClientCode = Renderer.Start() ) {
        // Any server-side code placed in here will render to client-side string
        X.MessageBox.Alert( "Test", "This is a Test." ).Show();
    }
    Btn1.Listener.Click.Handler = Renderer.ToString();
    or
    var Renderer = new Ext.Net.Renderer();
    X.StartRender( Renderer );
    // Any server-side code placed before X.EndRender will render to client-side string
    X.MessageBox.Alert( "Test", "This is a Test." ).Show();
    X.EndRender( Renderer ); // restores render stream back to response
    Btn1.Listener.Click.Handler = Renderer.ToString();

    Anyway, I think this is enough practical examples to how it might look. You can decide the appropriate.

    Obviously a lot of code should be placeable inside client-side render sections. Internally, I don't know how you'd make this work, but my first thought would be by creating a temporary SelfRenderingPage for the client-render section with dynamic on.

    But I'm hoping through this sample, you can see the value of wishing to render partial server-side code into snippets other server-side code would otherwise create as a response. It just seems to me that you already have the entire framework to make this work. You're just missing the technical infrastructure to render to anything but a response. In fact you have a way to do that too, minus a convention to create a snippet of client-side code. The real question is how close aren't you?

    Moreover, an extension to this would allow Webservices ComponentLoader to render code back to the client, no longer limited to just controls.
    Example:
    ComponentLoader.ToConfig( X.ClientCode( () => {
        // Any server-side code placed in here will render to client-side string
        X.MessageBox.Alert( "Test", "This is a Test." ).Show();
    } );
    The funny thing is, today, the only way to render code back to ComponentLoader is to include it in an empty usercontrol and include the code to render in the Page_Load. Wonky.
    Last edited by michaeld; Jan 12, 2014 at 6:11 AM.
  2. #2
    Hi Michael,

    Thanks for the feedback and ideas.

    Work on generating Js code is progressing on a couple different fronts. We will be introducing some of the features you suggest, although it will take time to finalize. This functionality is actively being worked on.
    Geoffrey McGill
    Founder & CEO
  3. #3
    Quote Originally Posted by geoffrey.mcgill View Post
    Work on generating Js code is progressing on a couple different fronts. We will be introducing some of the features you suggest, although it will take time to finalize. This functionality is actively being worked on.
    That's all I needed to hear. Thanks.
  4. #4
    Quote Originally Posted by geoffrey.mcgill View Post
    Hi Michael,

    Thanks for the feedback and ideas.

    Work on generating Js code is progressing on a couple different fronts. We will be introducing some of the features you suggest, although it will take time to finalize. This functionality is actively being worked on.
    Very good idea! Can we expect something in 2.5?
  5. #5
    I got a little impatient and decided to try this implementation myself. I posted the code here:
    http://forums.ext.net/showthread.php...lers)&p=124582
  6. #6
    I don't know if I noted this here, but I got this working in the link above. I had to branch Ext.Net a little though to get it to work reliably. Not sure it's how you'd do it. I'm sure you could fine tune to be a bit more efficient, but it was surprisingly simple.
  7. #7
    Hello everybody,

    We were working on something very related to the discussion. You might be interested to read this post.
    http://forums.ext.net/showthread.php...Bridge-Is-Open

Similar Threads

  1. [CLOSED] X.msg.alert: Server side vs Client side
    By FpNetWorth in forum 2.x Premium Help
    Replies: 2
    Last Post: Dec 28, 2012, 10:17 AM
  2. Replies: 3
    Last Post: Dec 26, 2011, 2:32 PM
  3. Replies: 1
    Last Post: Dec 01, 2010, 6:14 PM
  4. Replies: 4
    Last Post: Mar 19, 2010, 12:35 PM
  5. Replies: 6
    Last Post: Sep 01, 2009, 2:06 PM

Posting Permissions