ElementID field is not found in compile time in InputEventArgs args.Container.

Using the TextBox control I use Input="@((InputEventArgs args) => OnInputField(args, a))". During runtime args has a field "ElementID" in args.Container but in development and build, the field isn't found. Is there a way to get the value?

Actually what I'm trying to get is the ID of the field. I checked the
args.Container.ID but the value is blank.

9 Replies 1 reply marked as answer

SN Sevvandhi Nagulan Syncfusion Team July 23, 2020 06:36 AM UTC

Hi J, 


Greetings from Syncfusion support. 


We checked the reported requirement.  You can get the ID of the component from the  component reference(@ref). Refer to the code below, 


<SfTextBox @ref="textboxObj" Placeholder="Enter a Numeric Values" Input="OnInput"></SfTextBox> 
 
@code { 
 
    SfTextBox textboxObj; 
 
    public void OnInput(InputEventArgs args) 
    { 
        Console.WriteLine(args.Container.Id); 
        Console.WriteLine(textboxObj.ID); 
    } 
} 
  

Regards, 
Sevvandhi N 



J j July 23, 2020 01:17 PM UTC

Thank you for the reply, but actually I didn't use that approach because the TextBox control is auto-generated by a for loop, therefore it's dynamic. So declaring like SfTextBox textboxObj;  may not be possible. Maybe there's a better way?


SN Sevvandhi Nagulan Syncfusion Team July 24, 2020 08:51 AM UTC

Hi j, 


We can get the element id from the args.Conatiner. We checked the reported issue in the 18.2.46 version. Refer to the screenshot below, 



 




If still issue persists, could you please modify the above sample to replicate the issue. 


Regards, 
Sevvandhi N 


Marked as answer

J j July 25, 2020 01:15 AM UTC

Hello it doesn't appear to be correct. Here's what I found.

The output of textboxObj.ID are the same for all 3 textboxes.
Real textboxes ID's of the  3 is found on the sample attached file.

I checked it by copying the auto-generated html in the browser and copy it to a text editor.

Thanks.

Attachment: Syncfusion_id_issue_3efc1ef9.zip


SN Sevvandhi Nagulan Syncfusion Team July 27, 2020 07:54 AM UTC

Hi j, 


Thanks for the update. 

When you dynamically render using loop, we could not take the Id for the component. So, could you please clarify the purpose or scenario for taking the component ID?.  Upon that basis we check test other possibilities to achieve your requirement. 

Regards, 
Sevvandhi N 



J j July 28, 2020 07:16 AM UTC

One purpose is I am calling the specific component from JavaScript which sets the focus.

I have actually created a work-around to fulfill this.
I just generate my own id within the loop and assign it to id attribute like
@for(int i = 0; i < item.Count; i++)
{
   <SfTextBox id="@($"myTextbox-{i}")" Placeholder="@inputName"/>
}

In that way, textbox's id is created dynamically distinct.


SN Sevvandhi Nagulan Syncfusion Team July 29, 2020 05:53 AM UTC

Hi J, 


We are glad to know that you have find a solution. Please let us know if you need any other further assistance. 

Regards, 
Sevvandhi N 



JM Juan Montoya August 20, 2020 07:54 PM UTC

I am trying to implement something similar but when I use this code:


public void OnBlurField(FocusOutEventArgs args, string ElementName)
{
     string test=ElementName;
}

The build fails and I get no errors.

Any idea would be appreciated.




JM Jeyanth Muthu Pratheeban Sankara Subramanian Syncfusion Team August 21, 2020 12:38 PM UTC

Hi Juan,

Thanks for your update.

We have checked the reported requirement. We suggest you to call the blur event callback method as like below. We have prepared sample and kindly check the same in the attachment.


 
<SfTextBox id="@($"myTextbox-{i}")" Placeholder="@inputName" Blur=@((e)=>OnBlur(e, "MyName"))/> 



 
public void OnBlur(FocusOutEventArgs args, string Myname) 
    { 
        this.IsBlur = true; 
        this.AddtionalValue = Myname; 
    } 
 


Hope this helps to achieve your requirement.

Regards, 
Jeyanth.

 


Loader.
Up arrow icon