this.getCmp<T> issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    this.getCmp<T> issue

    I use Ext.Net Razor Pages template project.
    The server code Label lbl = this.GetCmp<Label>("lbl") returns label object.
    But label's Text and Html properties are just empty strings ("").
    However assignment lbl.Text = "some string"; works fine.

    The code for Ext.Net Razor Pages:
    Vew
    @page  "{handler?}"
    @model ExtDemo1.Pages.DirectEventsModel
    @{
        ViewData["Title"] = "DirectEvent";
        var X = Html.X();
    }
    <ext-section target="Main">
        <ext-container region="Center" scrollable="true" paddingAsString="30 20 30 50">
            <content>
                <h1>DirectEvent</h1>
                <ext-button text="Click Direct" onDirectClick="ButtonClick" />
                <ext-label id="lbl" text="ext-label"></ext-label>
            </content>
        </ext-container>
    </ext-section>
    Controller
    using System;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    using Ext.Net;
    using Ext.Net.Core;
    using MojeeIO;
    
    namespace ExtDemo1.Pages
    {
        public class DirectEventsModel : PageModel
        {
            public void OnGet()
            {
            }
            public IActionResult OnPostButtonClick(string message = "default text")
            {
                Label lbl = this.GetCmp<Label>("lbl");
                var txt = lbl.Text;              // returns empty string
                lbl.Text = $"{txt} {message}";   // works fine
                return this.Direct();
            }
        }
    }
  2. #2
    Hello, @VADIM!

    You are not going to get the contents of client-side components with this.GetCmp<T>(). It is a handle to assign values to components but there's no way to know what's currently in the component client-side unless said contents are actually passed as extra parameters.

    You can pass a whole component as an ExtraParam (and the direct event handler would have the component class as one of its arguments) but usually what you need is just a field, so you could then only pass the current label value to the direct events with the same extraParams approach you used in your previous thread.

    Let us know if it is not clear how you should proceed with the code and we'll point exactly what you should change in the provided test case to fetch the current label value in the component. There are other threads here in Ext.NET forums also discussing some advanced aspects and details on parameters passing. For instance, this post should be interesting for you:

    - Post #4 in DirectEvents and CodeBehind. Although in code behind, you can use the same value concept (which wraps a function) to get actual current value of a parameter when the event is triggered -- useful to pass form field values and grid selection (in that case), for instance.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 3
    Last Post: Dec 05, 2012, 1:38 PM
  2. [CLOSED] Pecilluar issue in the DropDown, UI Issue
    By Shanth in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 22, 2012, 12:02 PM

Posting Permissions