[CLOSED] passing ext.net controls to controller function

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] passing ext.net controls to controller function

    Hi,

    I have a scenario where i need to add controls to container dynamically. I need to pass the formpanel container object in my view to controller function and the function will add ext controls to the formpanel container based on some logic. We are using MVC pattern. How do I implement this.

    Thanks
    ANulekha
    Last edited by Daniil; Feb 21, 2012 at 6:43 PM. Reason: [CLOSED]
  2. #2
    Hi,

    There is no way to pass a whole control to a controller action.

    But you only need to pass its id.

    Please look at the example.

    Example View
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net.MVC Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:FormPanel ID="FormPanel1" runat="server" />
            <ext:Button runat="server" Text="Add a TextField">
                <DirectEvents>
                    <Click Url="/Test/AddTextField">
                        <ExtraParams>
                            <ext:Parameter Name="containerId" Value="#{FormPanel1}" Mode="Value" />
                        </ExtraParams>
                    </Click>
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
    Example Controller Action
    public ActionResult AddTextField(string containerId)
    {
        TextField tf = new TextField()
            {
                FieldLabel = "FieldLalel",
                Text = "Hello World!"
            };
    
        string script = tf.ToScript(RenderMode.AddTo, containerId);
    
        return new AjaxResult(script);
    }
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    There is no way to pass a whole control to a controller action.

    But you only need to pass its id.

    Please look at the example.

    Example View
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net.MVC Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:FormPanel ID="FormPanel1" runat="server" />
            <ext:Button runat="server" Text="Add a TextField">
                <DirectEvents>
                    <Click Url="/Test/AddTextField">
                        <ExtraParams>
                            <ext:Parameter Name="containerId" Value="#{FormPanel1}" Mode="Value" />
                        </ExtraParams>
                    </Click>
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
    Example Controller Action
    public ActionResult AddTextField(string containerId)
    {
        TextField tf = new TextField()
            {
                FieldLabel = "FieldLalel",
                Text = "Hello World!"
            };
    
        string script = tf.ToScript(RenderMode.AddTo, containerId);
    
        return new AjaxResult(script);
    }
    Hi Daniil,

    What if i need to add multiple controls to the same container in a swtich case condition?

    Thanks
    Anulekha
  4. #4
    It's not a problem.

    Example
    public ActionResult AddTextField(string containerId)
    {
        TextField tf1 = new TextField()
            {
                FieldLabel = "FieldLalel1",
                Text = "Hello World 1!"
            };
    
        string script = tf1.ToScript(RenderMode.AddTo, containerId);
    
        TextField tf2 = new TextField()
        {
            FieldLabel = "FieldLalel 2",
            Text = "Hello World 2!"
        };
    
        script += tf2.ToScript(RenderMode.AddTo, containerId);
    
        return new AjaxResult(script);
    }
  5. #5
    Quote Originally Posted by Daniil View Post
    It's not a problem.

    Example
    public ActionResult AddTextField(string containerId)
    {
        TextField tf1 = new TextField()
            {
                FieldLabel = "FieldLalel1",
                Text = "Hello World 1!"
            };
    
        string script = tf1.ToScript(RenderMode.AddTo, containerId);
    
        TextField tf2 = new TextField()
        {
            FieldLabel = "FieldLalel 2",
            Text = "Hello World 2!"
        };
    
        script += tf2.ToScript(RenderMode.AddTo, containerId);
    
        return new AjaxResult(script);
    }
    HI Daniil,

    I am getting the below error:

    "Error executing child request for handler 'Ext.Net.SelfRenderingPage'."

    Thanks
    ANulekha
  6. #6
    Please provide a sample how you are trying.

    I have no error with my test case.
  7. #7
    Quote Originally Posted by Daniil View Post
    Please provide a sample how you are trying.

    I have no error with my test case.
    Hi Daniil,

    Below is the sample code.

    aspx file
    
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Ext.Net.MVC Example</title>
        <script type="text/javascript">
            var AddCustomFields = function (controls, args) {
                Ext.Ajax.request({ method: 'POST', url: '/Home/AddTextField/', params: { containerId: args.container.id} });
            }
        </script>
    </head>
    <body>
    
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel ID="ReqCustomFldsPnl" runat="server" Border="false" BodyStyle="background-color: #DFE8F6"
            Padding="5" AutoDoLayout="true" Layout="FitLayout">
            <Items>
                <ext:FieldSet ID="fldstReqCustomFlds" runat="server" Title="CustomFields" AutoHeight="true"
                    Padding="5" LabelWidth="75" CollapseMode="Mini" AutoDoLayout="true" Collapsed="true"
                    Collapsible="true" Layout="FormLayout" AnchorHorizontal="95%" AutoScroll="true"
                    AnchorVertical="100%">
                    <Items>
                        <ext:FormPanel ID="IRReqHdrCustomFieldsContainer" runat="server" Padding="6" BodyStyle="background-color: #DFE8F6"
                            ForceLayout="true" Layout="FormLayout" HideLabels="true" BodyBorder="false" Border="false">
                        </ext:FormPanel>
                    </Items>
                    <Listeners>
                        <Expand Handler="AddCustomFields('undefined',{container:#{IRReqHdrCustomFieldsContainer},entityType:'Issue Requisition Header',entityID:''}); " />
                    </Listeners>
                </ext:FieldSet>
            </Items>
        </ext:Panel>
    </body>
    </html>
    
    controller 
    public ActionResult AddTextField(string containerId)
            {
                TextField tf1 = new TextField() { FieldLabel = "FieldLalel1", Text = "Hello World 1!" };
                string script = tf1.ToScript(RenderMode.AddTo, containerId); 
                TextField tf2 = new TextField() { FieldLabel = "FieldLalel 2", Text = "Hello World 2!" }; 
                script += tf2.ToScript(RenderMode.AddTo, containerId);
                TextField textfield = new TextField();
                textfield.FieldLabel ="Test";
                textfield.AllowBlank = true;//TODO
                textfield.IndicatorIcon = Icon.BulletRed;
                textfield.Enabled = true;
                textfield.ReadOnly = true;
                script = script + textfield.ToScript(RenderMode.AddTo, containerId);
                return new AjaxResult(script);
            }
    Thanks
    Anulekha
  8. #8
    I was unable to reproduce the error you mentioned:
    "Error executing child request for handler 'Ext.Net.SelfRenderingPage'."
    I can see a correct response of the request.

    Please update from SVN and re-test.

    Though, the controls are not rendered, because you used Ext.Ajax.request. In that case you should manage a response manually.

    I would suggest you to use Ext.net.DirectMethod.request. It will look in similar the calling WebService in this example:
    https://examples1.ext.net/#/Events/D...ds/WebService/
    Last edited by Daniil; Feb 16, 2012 at 12:53 PM.
  9. #9
    Quote Originally Posted by Daniil View Post
    I was unable to reproduce the error you mentioned:


    I can see a correct response of the request.

    Please update from SVN and re-test.

    Though, the controls are not rendered, because you used Ext.Ajax.request. It that case you should manage a response manually.

    I would suggest you to use Ext.net.DirectMethod.request. It will look in similar the calling WebService in this example:
    https://examples1.ext.net/#/Events/D...ds/WebService/
    Hi Daniil,

    That worked. Can i know why its not working using ajax request?

    Thanks
    Anulekha
  10. #10
    Please clarify did you just replace Ext.Ajax.request with Ext.net.DirectMethod.request and the error below is gone?
    "Error executing child request for handler 'Ext.Net.SelfRenderingPage'."
    I mean did not you update from SVN?
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] [RAZOR] How to access ext.net controls from controller method
    By gets_gui in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Sep 13, 2012, 8:12 AM
  2. [CLOSED] Passing function result as value of a parameter
    By RCN in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 13, 2012, 11:43 AM
  3. [CLOSED] passing data from controller to 'RemoteActionSuccess'
    By jesperhp in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 16, 2011, 6:48 PM
  4. Add controls via MVC Controller (DirectResponse?)
    By peter.campbell in forum 1.x Help
    Replies: 2
    Last Post: Jan 28, 2011, 8:33 AM
  5. Replies: 3
    Last Post: Aug 21, 2010, 5:26 AM

Posting Permissions