We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dialog with child control becomes null on hide.

I have a control as below 

<SfDialog @ref="@UserDialogObj" Visible="false"  AllowDragging="true" EnableResize="true" ShowCloseIcon="true" Width="960px" Height="480px">

    <DialogTemplates>

        <Header>

            User Details

        </Header>

        <Content>

            <Control_User @ref="@controlUserObj"></Control_User>

        </Content>

    </DialogTemplates>

</SfDialog>


If i load the page as above, the control  controlUserObj is null and cannot access any properties.  If Visible=true , then  controlUserObj is accessible.   

What's the best practice to show hide Dialog with a child control?



3 Replies 1 reply marked as answer

VJ Vinitha Jeyakumar Syncfusion Team February 10, 2023 02:01 PM UTC

Hi Anthony,


We have tried to replicate the reported issue at our end by rendering a custom component inside the Dialog content and accessed the component's instance in the Dialog open event. please check the sample and code below for your reference.


Code snippet:
<SfDialog @ref="DialogObj" Width="450px" ShowCloseIcon="true" Visible=false>
    <DialogEvents Opened="@DialogOpen"></DialogEvents>
    <DialogTemplates>
        <Header>
            <div>Dialog Header</div>
        </Header>
        <Content>
            <CustomComponent @ref="rteObj"></CustomComponent>
        </Content>
    </DialogTemplates>
</SfDialog>
@code {
    SfDialog DialogObj;
    SfRichTextEditor RteObj;
    CustomComponent rteObj;
    private void OpenDialog()
    {
        this.DialogObj.ShowAsync();
    }
    private void DialogOpen()
    {
        rteObj.refreshUI();
    }
}



If it doesn't meet your requirements, please get back to us with the issue replicating entire code snippet or modify the attached sample with the issue reproducing code for further validation.

Regards,
Vinitha

Marked as answer

AN Anthony February 11, 2023 04:36 AM UTC

It appears removing the @ in the @ref property helped :)  thank you

<SfDialog @ref="UserDialogObj" Visible="false"  AllowDragging="true" EnableResize="true" ShowCloseIcon="true" Width="960px" Height="480px">

    <DialogTemplates>

        <Header>

            User Details

        </Header>

        <Content>

            <Control_User @ref="controlUserObj"></Control_User>

        </Content>

    </DialogTemplates>

</SfDialog>



VJ Vinitha Jeyakumar Syncfusion Team February 13, 2023 04:47 AM UTC

Hi Anthony,


We are glad that your issue has been resolved.

Regards,
Vinitha

Loader.
Live Chat Icon For mobile
Up arrow icon