Articles in this section
Category / Section

How to disable the text entry in ASP.NET Web Forms DropDownCalendar?

1 min read

 

You can disable the entry of text by rewriting the existing onkeydown event of DropDownCalendar control Textbox element. And the keys pressed can be validated in this event. Please refer the below code snippet

C#

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

//DropDownCalendar control attributes collections should be set before

''RenderChildren'' method.

CustomDropDownControl DropDownCalendarControl1 = new CustomDropDownControl();

//Add dropdown control in the PlaceHolder control list

PlaceHolder1.Controls.Add(DropDownCalendarControl1);

}

}

public class CustomDropDownControl : DropDownCalendarControl

{

protected override void RenderChildren(HtmlTextWriter writer)

{

//Insert the Validation script here.

this.m_textBox.Attributes["onkeydown"] = "if(!(event.keyCode<=57 && event.keyCode

=48)){if(!(event.keyCode <= 90 && event.keyCode >=65)){if(!(event.keyCode<=122 &&

event.keyCode >=97)){" + this.m_textBox.Attributes["onkeydown"] + "}else return

false;}else return false;}else return false;";

base.RenderChildren(writer);

}

}

VB

Public partial Class _Default : Inherits System.Web.UI.Page

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

  Dim DropDownCalendarControl1 As CustomDropDownControl = New

CustomDropDownControl()

PlaceHolder1.Controls.Add(DropDownCalendarControl1)

 End Sub

End Class

Public Class CustomDropDownControl : Inherits DropDownCalendarControl

 Protected Overrides Sub RenderChildren(ByVal writer As HtmlTextWriter)

  Me.m_textBox.Attributes("onkeydown") = "if(!(event.keyCode<=57 &&

event.keyCode >=48)){if(!(event.keyCode <= 90 && event.keyCode

>=65)){if(!(event.keyCode<=122 && event.keyCode >=97)){" &

Me.m_textBox.Attributes("onkeydown") & "}else return false;}else return false;}else return

false;"

  MyBase.RenderChildren(writer)

 End Sub

End Class

Note:

A new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.

You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied