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.
Unfortunately, activation email could not send to your email. Please try again.

How to disable the text entry in DropDownCalendar control?

 

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

Please refer the below sample which illustrates the above :

http://websamples.syncfusion.com/samples/tools.web/5.2.0.25/i39414/main.htm

Article ID: Published Date: Last Revised Date: Platform: Control:
1713 04/30/2011 07/10/2014 ASP.NET Web Forms (Classic) DropDownCalendarControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.