[CLOSED] Adding code behind controls to form

  1. #1

    [CLOSED] Adding code behind controls to form

    Hi

    I know that it has something to do with the adding my code behind controls to the form controls when creating them on the fly by direct method. I thought I am doing it but I still have some troubles to see everything though.

    What am I doing wrong in this example? I just want to be able to control the store in the first window...

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                
            }
        }
    
        [DirectMethod]
        public void createWindowOne()
        {
            Window win = new Window
            {
                ID = "wOne",
                Title = "Window One",
                Modal = true,
                Width = 200,
                Height = 200,
                Items =
                {
                    new GridPanel {
                        ID = "gpWONE",
                        Height = 100,
                        Store = { 
                            new Ext.Net.Store
                            {
                                ID = "STORE1",
                                Model = {
                                    new Ext.Net.Model {
                                        Fields = { new Ext.Net.ModelField { Name = "ID", Type = Ext.Net.ModelFieldType.String } },
                                        IDProperty = "ID"
                                    }
                                }
                            }
                        },
                        ColumnModel = { Columns = { new Ext.Net.Column { Text = "ID", DataIndex = "ID", MenuDisabled = true, Width = 100 } } }
                    },
                    new Ext.Net.Button { Text = "Create Window Two", Handler = "App.direct.createWindowTwo();"}
                }
            };
            this.Form.Controls.Add(win);
            win.Render(this.Form);
        }
    
        [DirectMethod]
        public void createWindowTwo()
        {
            Window win = new Window
            {
                ID = "wTwo",
                CloseAction = Ext.Net.CloseAction.Destroy,
                Title = "Window Two",
                Modal = true,
                Items =
                {
                    new TextField { ID = "tfID", FieldLabel = "Insert ID", Width = 200 },
                    new Ext.Net.Button { ID = "btnWTWO", Text = "Get Store Count from Window One", Handler = "alert(#{STORE1}.getCount()); #{wTwo}.close();" }
                }
            };
            this.Form.Controls.Add(win);
            win.Render(this.Form);
        }
    
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title></title>
    
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <ext:Button runat="server" Text="Create Window One" Handler="App.direct.createWindowOne();"></ext:Button>
    
        </form>
    </body>
    </html>
    thank you for any input.

    best regards and a happy new year!
    Last edited by Daniil; Jan 08, 2014 at 2:37 PM. Reason: [CLOSED]
  2. #2
    Replace '#{STORE1}' by 'App.STORE1' and '#{wTwo}' by 'App.wTwo' because those controls are not accessable during second window creation
  3. #3
    I would use string.Format("alert({0}.getCount()); {1}.close();", STORE1.ClientID, wTwo.ClientID ) for the handler to ensure they change with idmode usage.
  4. #4
    @Vladimir

    Thank you. The "App.xxx" does the trick but I only need it for the store. The window ID is the same window I am generating at that time so the .close() is working.

    @michaeld

    Could you elaborate what do you mean with IDmode? I have never used it yet and I have no clue what it is. A hint or a link would be very appreciated. Your version didn't yet work for me because I can't reference the STORE1.ClientID at that time during the creation of the second window.

    Thank you very much both or you.
  5. #5
    Quote Originally Posted by michaeld View Post
    I would use string.Format("alert({0}.getCount()); {1}.close();", STORE1.ClientID, wTwo.ClientID ) for the handler to ensure they change with idmode usage.
    @michaeld - Using the Id token should output the correct client-side Id based on the .IDMode.

    Using either #{STORE1} or this.Store1.ClientID should render the same value, no matter what the .IDMode.
    Geoffrey McGill
    Founder
  6. #6
    Where can I get more information about this IDmode?
  7. #7
    Some details of IDMode you can find here:
    http://forums.ext.net/showthread.php...ll=1#post73893

    Most of the statements are actual for v2 as well.
  8. #8
    @Daniil

    Wonderfull, thank you. You can close this thread - all my questions are answered.

Similar Threads

  1. [CLOSED] Is it possible to control child form controls from main form?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 13, 2012, 12:24 PM
  2. Adding Controls in Code Behind Causes Event Error
    By niceguymattx in forum 1.x Help
    Replies: 2
    Last Post: May 21, 2010, 9:49 AM
  3. Adding The Resource File To Form
    By Dinesh.T in forum 1.x Help
    Replies: 0
    Last Post: Dec 11, 2009, 2:13 AM
  4. Adding Form fields at run time
    By sz_146 in forum 1.x Help
    Replies: 1
    Last Post: Feb 10, 2009, 6:18 PM
  5. Dynamically adding form fields
    By sz_146 in forum 1.x Help
    Replies: 4
    Last Post: Nov 11, 2008, 11:10 AM

Posting Permissions