Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'System.Web.UI.WebControls.TextBoxMode' does not contain a definition for 'Date'

Tags:

asp.net

Error Message: 'System.Web.UI.WebControls.TextBoxMode' does not contain a definition for 'Date'

Code:

<asp:TextBox ID="lastDate" runat="server" autocomplete="off" TextMode="Date" ></asp:TextBox>

                 <ajax:CalendarExtender ID="lastDate_CalendarExtender" runat="server" 
                     Enabled="True" TargetControlID="lastDate">
like image 283
prashanthi kontemukkala Avatar asked Apr 10 '14 08:04

prashanthi kontemukkala


3 Answers

Maybe I am quite late in adding my 2 cents but I thought this might help some people in future. As mentioned by Rob, since .Net 4.5 you can use TextMode="Date" for your asp:TextBox but the browser support might be limited as this will render your TextBox as HTML5 date type textbox in the page output. Most modern browsers do support HTML5 as of the time I am writing this.

However if this is what you desire, then there is no problem with your Markup.

<asp:TextBox ID="lastDate" runat="server" autocomplete="off" TextMode="Date" />

If you see this error message in Visual Studio Visual Studio it is most probably because of incorrect target framework version.

Change the Target-Framework property in your Web.Config as following to get rid of this error.

Web.Config > configuration > system.web > compilation

<compilation debug="true" defaultLanguage="C#" targetFramework="4.5" />

Hope this helps

like image 176
EMalik Avatar answered Nov 20 '22 19:11

EMalik


Check the following MSDN Link

The Description says Textmode property of asp text box can only be set to following 3 options.

Password: This mode can be selected if you want to show the input in textbox as dot's (Password type).

Single Line: Use to retain the textbox as single line field.

Multiline: Use to make textbox as commentbox , i.e to have multiple lines...

I think all TextBoxMode values worked with .net framework 4.0 or less, now these three values are supported.

like image 26
Kira Avatar answered Nov 20 '22 17:11

Kira


Supported in .net 4.5, but browser support is partial

With ASP.net 4.5 you can use this property with more values like Date - see the documentation for TextBoxMode. However, as of Sep 2014, caniuse.com reports only 50% of users will be able to use it properly. If you know the browsers you're targeting have support, then remove the CalendarExtender and change your project to target .net 4.5.

There are issues publishing TextMode='Date' in VS2012

Additionally, if you're publishing with pre-compilation set, you need to have 'Allow precompiled site to be updatable' checked or it will error (at least in VS2012 - if I find a solution to this I'll update my answer).

Fall-back to ASP.net components to do this work

However, you can instead use the ASP.net CompareValidator along with the CalendarExtender

<asp:TextBox ID="lastDate" runat="server" autocomplete="off" />
<ajax:CalendarExtender ID="lastDate_CalendarExtender" runat="server" 
    Enabled="True" TargetControlID="lastDate" />
<asp:CompareValidator ID="CompareValidator2" runat="server"
    ControlToValidate="txtDateDiscIssued"
    ErrorMessage="* invalid"
    Operator="DataTypeCheck"
    Type="Date" />
like image 2
Rob Church Avatar answered Nov 20 '22 17:11

Rob Church