View Full Version : this.getCmp<T> issue

Mar 31, 2021, 2:17 PM
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:

@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">
<ext-button text="Click Direct" onDirectClick="ButtonClick" />
<ext-label id="lbl" text="ext-label"></ext-label>


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();

Mar 31, 2021, 7:59 PM
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 (https://forums.ext.net/showthread.php?63113).

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 (https://forums.ext.net/showthread.php?63066&p=286309#post286309). 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!