Getting input from dynamic textbox

I just created a textbox together with a dynamic button with guide from the documentation.
https://blazor.syncfusion.com/documentation/textbox/how-to/create-components-dynamically/
I want to copy the input on textbox from user yet I have no idea how to do it. The only clue I have from the documentation was these lines below from @code. 
I am wondering how to fix the codes here to get the input and save it as a string variable

public RenderFragment CreateTokenComponent() => builder =>
    {
        builder.OpenComponent(0, typeof(SfTextBox));
        builder.AddAttribute(1, "Placeholder", "Token Input");
        builder.CloseComponent();

    };


The attachment contains images of my codes.
Thanks in advance.


Attachment: qs_1580e38a.zip

1 Reply 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team October 28, 2020 02:11 PM UTC

Hi Luke, 

Greetings from Syncfusion support. 

We have prepared sample as per your requirement for dynamically render the Textbox component using RenderFragment. You can get the user input in ValueChange event of Textbox as like below code snippet. 

<SfButton ID="dynamic-button" Content="Render TextBox" @onclick="RenderComponent"></SfButton> 
@code { 
    private RenderFragment DynamicRender { get; set; } 
    private RenderFragment CreateComponent() => builder => 
    { 
        builder.OpenComponent(0, typeof(SfTextBox)); 
        builder.AddAttribute(1, "ID", "MyDynamicId"); 
        builder.AddAttribute(2, "Placeholder", "Enter your text"); 
        builder.AddAttribute(3, "ValueChange",  Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<Microsoft.AspNetCore.Components.EventCallback 
<Syncfusion.Blazor.Inputs.ChangedEventArgs>>(Microsoft.AspNetCore.Components.EventCallback.Factory.Create< 
Syncfusion.Blazor.Inputs.ChangedEventArgs>(this, ((e) => OnChange(e))))); 
        builder.CloseComponent(); 
    }; 
    private void RenderComponent() 
    { 
        DynamicRender = CreateComponent(); 
    } 
    private void OnChange(ChangedEventArgs args) 
    { 
        string test = args.Value; 
    } 
} 

 


 
Kindly check with the above sample. Please get back us if you need further assistance. 

Regards, 
Ponmani M 


Marked as answer
Loader.
Up arrow icon