@ref does not work for controls within a Tab

If you start the project, you will see in the console that the @ref for the embedded TextBox is null.

How can I get a reference ?

Attachment: TextBoxesRefs_4418126d.7z

1 Reply 1 reply marked as answer

AK Alagumeena Kalaiselvan Syncfusion Team July 13, 2020 10:53 AM UTC

Hi Brice, 

Thanks for contacting Syncfusion support. 

We have checked your reported issue “ref does not work for controls within Tab” with shared sample and during OnAfterRender the content of Tab may not completely initialized. So, we suggest you to use Created event for Tab component to get the reference of its content which have any others components as like Textbox. We have modified your sample for the reference. 

 
<SfTextBox ID="First" @ref="@firstTextBox" Placeholder="First"></SfTextBox> 
<SfTab ID="Tabs"> 
    <TabEvents Created="OnCreate"></TabEvents> 
    <TabItems> 
        <TabItem> 
            <ChildContent> 
                <TabHeader Text="grid test" /> 
            </ChildContent> 
            <ContentTemplate> 
                <SfTextBox ID="Second" @ref="@secondTextBox" Placeholder="Second"></SfTextBox> 
            </ContentTemplate> 
        </TabItem> 
    </TabItems> 
</SfTab> 
 
@code 
{ 
    SfTextBox firstTextBox; 
    SfTextBox secondTextBox; 
 
    protected override void OnAfterRender(bool firstRender) 
    { 
        Console.WriteLine("First = " + firstTextBox?.ToString()); 
        base.OnAfterRender(firstRender); 
    } 
    public void OnCreate() 
    { 
        Console.WriteLine("Second = " + secondTextBox?.ToString());  /*To get the reference of second Textbox*/ 
    } 
} 


Kindly get back to us, if you need further assistance. 

Regards 
Alagumeena.K 


Marked as answer
Loader.
Up arrow icon