[Razor] - How do I access Ext objects through JavaScript?

  1. #1

    [Razor] - How do I access Ext objects through JavaScript?

    About 9 months ago I was using Ext.Net v1, with ASP.NET forms.

    Now I have just started using v2 with razor. Previously I was able to access any Ext control in JavaScript by it's ID e.g. TextField_ID.setValue("test")

    Now if I use the ID in a JavaScript function, it does not return the Ext object.

    In the example below, I want the populateForm function to set the form values after a combo box item is selected, how should I do this?

    @using Ext.Net
    @using Ext.Net.MVC
    @model Admin.Models.Customer
    @{
        ViewBag.Title = "Create";
        Layout = "~/Views/Shared/_Layout_ext.cshtml";
    }
    
    
    <script type="text/javascript">
        var populateForm = function (combo, records, eOpts) {
            var data = records[0].data;
    
            //CompanyName is the wrong way to access the TextField
            CompanyName.setValue(data.CompanyName);
        };
    </script>
    
    
    @using (Html.BeginForm())
    {
        @(@Html.X().FormPanel()
            .Title("Create Customer")
            .BodyPadding(5)
            .AutoHeight(true)
            .Defaults(d =>
                          {
                              d.Add(new Parameter("LabelWidth", "200"));
                              d.Add(new Parameter("LabelAlign", "right"));
                              d.Add(new Parameter("Width", "500"));
                          })
            .Items(i =>
                       {
    
    
                           var cb = @Html.X().ComboBox()
                               .DisplayField("CompanyName")
                               .ValueField("CompanyID")
                               .FieldLabel("Pull data from InfusionSoft")
                               .HideBaseTrigger(true)
                               .EmptyText("Search company name in InfusionSoft")
                               .ID("InfusionSoftCompanyId")
                               .MinChars(1)
                               .Store(s =>
                                          {
                                              var store = new Store { AutoLoad = false };
                                              var proxy = new AjaxProxy { Url = "/webservices/InfusionSoft/FindCompany.ashx" };
                                              var reader = new JsonReader { Root = "companies", TotalProperty = "total" };
    
    
                                              proxy.ActionMethods.Read = HttpMethod.POST;
                                              proxy.Reader.Add(reader);
    
    
                                              var model = new Model();
                                              model.Fields.Add(new ModelField("CompanyID"));
                                              model.Fields.Add(new ModelField("CompanyName"));
    
    
                                              store.Proxy.Add(proxy);
                                              store.Model.Add(model);
    
    
                                              s.Add(store);
                                          })
                               .QueryMode(DataLoadMode.Remote)
                               .QueryDelay(900)
                               .Listeners(l => { l.Select.Fn = "populateForm"; });
    
    
                           i.AddRange(new AbstractComponent[]
                                          {
                                              cb,
                                              new TextField {ID = "CompanyName", FieldLabel = "Company Name"},
                                              new TextField {ID = "Addr1", FieldLabel = "Addr1"},
                                              new TextField {ID = "Addr2", FieldLabel = "Addr2"},
                                              new TextField {ID = "Addr3", FieldLabel = "Addr3"},
                                              new TextField {ID = "Addr4", FieldLabel = "Addr4"},
                                              new TextField {ID = "PostCode", FieldLabel = "Post Code"},
                                              new TextField {ID = "CountryId", FieldLabel = "Country"},
                                              new TextField {ID = "Phone1", FieldLabel = "Phone 1"},
                                              new TextArea {ID = "Notes", FieldLabel = "Notes", MinHeight = 200, AutoHeight = true},
                                          });
                       }))
        <div class="editor-label">
            Customer Credits
        </div>
        <div class="editor-field">
            This will be available after you save the new customer.
        </div>
        
    }
    <p>
        <div>
            @Html.ActionLink("Back to List", "Index")
        </div>
    </p>
  2. #2
    I just found out that App is the object I should be accessing.

    My next question is, am I trying to populate the form in the correct manor (using client JS), or is there a better way?

    Also, can you define the fields in a Store Model from a POCO?

    Thanks
    Last edited by mj.daly; Jun 08, 2012 at 2:32 PM.
  3. #3

    accessing Last row in the group, which is loaded in GridPanel

    Quote Originally Posted by mj.daly View Post
    I just found out that App is the object I should be accessing.

    My next question is, am I trying to populate the form in the correct manor (using client JS), or is there a better way?

    Also, can you define the fields in a Store Model from a POCO?

    Thanks

    hi,
    I am accessing the row of my grid through the Ext.net.DirectMethods.MethodName(par1,par2,...); --> Something like this,
    Ext.net.DirectMethods.MyMethod(records[0].data.QuoteNumber,records[1].data.RevisionNumber);

    But i want to get last record in the records[]....
    I tried with records[].data.RevisionNumber...
    records[Length].data.RevisionNumber...
    records[rowindex.Length].data.RevisionNumber...

    But i am not able to get the last record. Actually the list has been loaded into grid. So i want to send the Last row of that group to the server from client, which will be different each time.

    records[0], records[1], records[2] are working, but how to get the last one. I tried with firebug. but i couldnt access last record. Please help me with this.




    I got the solution,
    i tried with records[length].data.RevisionNumber instead of records[Length].data.RevisionNumber .
    there length is case sensitive....
    Last edited by sunilbp; Jul 10, 2012 at 1:41 PM. Reason: solution

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] Referencing page controls in JavaScript objects
    By PLoch in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Aug 16, 2011, 5:59 PM
  3. [CLOSED] Access ext objects from an Iframe?
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jun 24, 2010, 8:50 PM
  4. [CLOSED] Access ext objects in codebehind
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jun 22, 2010, 4:57 PM
  5. Access to objects created in codebehind
    By Tror in forum 1.x Help
    Replies: 1
    Last Post: Jun 22, 2010, 4:30 AM

Posting Permissions