New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Server-side Programming Overview
Overview of the Server-side APIs you can use to create and configure the Telerik WebForms OTPInnput Control.
Creating the OTPInput in the Markup
To create an OTPInput in the markup, add the RadOTPInput
element to the page and set its properties accordingly. You can find the properties in Properties article.
Example
ASP.NET
<telerik:RadOTPInput ID="RadOTPInput1" runat="server">
<ItemsCollection>
<telerik:OTPInputItem GroupLength="3" />
</ItemsCollection>
</telerik:RadOTPInput>
Creating the OTPInput dynamically
To create the OTPInput on the server, create a new instance of the RadOTPInput
object, set its properties and add it to the Controls collection of another control (e.g. PlaceHolder1
).
You can find the properties and enums in the following articles:
Example
C#
protected void Page_PreInit(object sender, EventArgs e)
{
RadOTPInput otpInput = new RadOTPInput()
{
Space = true,
Placeholder = "0-9",
Type = OTPInputType.Number
};
OTPInputItem item1 = new OTPInputItem()
{
GroupLength = 3
};
otpInput.ItemsCollection.Add(item1);
OTPInputItem item2 = new OTPInputItem()
{
GroupLength = 3
};
otpInput.ItemsCollection.Add(item2);
PlaceHolder1.Controls.Add(otpInput);
}
The PlaceHolder1
ASP.NET
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
Creating controls programmatically must be done in an early event such as PreInit (preferably), Init. For more details you can check out the ASP.NET Page Life-Cycle Events