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

How to add maxlength attribute ?

Its not clear how to use AddAttributes method because it accept object parameter.

1 Reply

GG Gopi Govindasamy Syncfusion Team August 14, 2019 12:20 AM

Hi Andrey Voronov, 
  
Greetings from Syncfusion support. 
 
The AddAttributes method  is used to add multiple attributes depending on the key-value pair to the input element of the textbox. So you can add the maxlength attributes using Dictionary type. We have prepared sample based on your requirement. Please find the code snippet and sample for your reference.  
 
<h4>TextBox</h4> 
 
<EjsTextBox @ref="TextBoxObj"></EjsTextBox> 
 
<button class="e-btn" @onclick="Clicked">Add Attributes</button> 
 
@code 
{ 
 
EjsTextBox TextBoxObj; 
 
public void Clicked() 
{ 
    TextBoxObj.AddAttributes(new Dictionary<string, object>() { { "maxlength", "12" } }); 
} 
} 
 
 
 
 
We would like to inform you that we have provided HtmlAttributes. By default, the HtmlAttributes property is available in Textbox. You can add the custom attribute to the textbox input element by using this property. 
 
The following code example demonstrates how to set the custom attribute to the textbox component using HtmlAttributes property. 
 
<h4>TextBox</h4> 
 
<EjsTextBox HtmlAttributes="@htmlAttribute"></EjsTextBox> 
 
 
@code 
{ 
private Dictionary<string, object> htmlAttribute { get; set; } = new Dictionary<string, object>() { 
            {"maxlength", "12" } 
            }; 
} 
 
 
 
Regards, 
Gopi G. 


Loader.
Live Chat Icon For mobile
Up arrow icon