Only number's field ASP.NET - css

I'd like to have special fields with ASP.NET, I use ASP:TextBox for my login page. The idea is : when you are in a mobile device, it recognizes the field and purpose a special keyboard with only numbers (my login page uses only numbers)
I tested that, but it doesn't works :
<asp:TextBox CssClass="LoginTxtBox" ID="Txt_nom" runat="server" AutoCompleteType="Disabled" ForeColor="Black" MaxLength="20" Width="100%" Height="30px" TextMode="Number"></asp:TextBox>
"Number isn't a member of System.UI.WebControls.TextBoxMode"
I checked and Number is a member of this. I don't understand why I can't debug with that. (I can launch the website with IIS, no issue)
Thanks for your help !

could you try:
<asp:TextBox CssClass="LoginTxtBox" ID="Txt_nom" runat="server" AutoCompleteType="Disabled" ForeColor="Black" MaxLength="20" Width="100%" Height="30px" type="Number"></asp:TextBox>
changed "TextMode" into "type".
see more info here: http://mobiforge.com/design-development/html5-mobile-web-forms-and-input-types

this will help:
<asp:TextBox ID="Txt_nom" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="Txt_nom" runat="server" ErrorMessage="Only Numbers allowed" ValidationExpression="\d+"></asp:RegularExpressionValidator>

Related

asp.net validators ends up in same place

I'm writing an application with multiple validators (date, required, regexp for format) on the same page. They validate correctly, but they turn up in the same place. That is, they don't turn up next to the validated field, they are appended to another validation error message next to a completely other field.
Here goes example code snippets:
Number:
<asp:RegularExpressionValidator class="IMSIValidators" runat="server" ErrorMessage="Enter digits only, no other characters" ControlToValidate="IMSIRangeTextBox" Display="Dynamic" ValidationGroup="AllValidators" ValidationExpression="[0-9]+"></asp:RegularExpressionValidator>
<p class="IMSIEditLabels">Operator: <asp:TextBox ID="OperatorTextBox" runat="server"></asp:TextBox></p>
<asp:RequiredFieldValidator runat="server" class="IMSIValidators" Text="Enter the customer" ControlToValidate="OperatorTextBox" Display="Dynamic" ValidationGroup="AllValidators"></asp:RequiredFieldValidator>
<p class="IMSIEditLabels">Requested by:<asp:TextBox ID="RequestedTextBox" class="IMSIEditInputItems" runat="server" ValidationGroup="AllValidators"></asp:TextBox></p>
<asp:RequiredFieldValidator runat="server" Text="Enter a full name" ControlToValidate="RequestedTextBox" Display="Dynamic"></asp:RequiredFieldValidator>
I've tried all ways that I can think of, such as setting Display="Dynamic" and ValidationGroup="AllValidators". No combination works for me.
I've tried to set their position in a CSS class, but then they came up on top of each other (which is logical).
Any input is greatly appreciated. I'm getting SO frustrated :)
//Eva-Lotta

Limit Input Type in a Textbox

I'm new to all this and trying to only allow numeric values to be entered into an existing TextBox in ASP.Net. I've got the code for this, but can't figure out where to put it in. If I do it like the below, it creates an additional box in the textbox (that works). How can I apply this limitation to the current textbox?
<asp:TableCell>
<asp:TextBox ID="txtS2" runat="server" Width="95%" AutoPostBack="true" OnTextChanged="WerklikChanged"></asp:TextBox>
<input type="text" onkeypress="filterDigits(event)"/>
</asp:TableCell>
Update:
I ended up using the below, which is not really what I wanted as it still only checks the field once I leave the field. I'll look into blocking the entry of letters completely at a later stage and post the answer here.
<asp:CompareValidator
ID="ProgrammaticID"
ControlToValidate="txtS2KoringA"
Type="Double"
Operator="DataTypeCheck"
ErrorMessage="Error Message"
Text=" Net nommers word toegelaat in die 'Werklik' velde"
ForeColor="Red"
BackColor="White"
SetFocusOnError="false"
Display="Dynamic"
runat="server">
</asp:CompareValidator>

ASP.NET Multiple Validation Controls on a single asp.net input control?

I have the following textbox alongwith its validators, but when I enter the correct text it fires up the RegularExpressionValidator error message, can't really figure out what I am doing wrong
<asp:TextBox ID="txtName" runat="server" onkeypress="return keyRestrict(event,'abcdefghijklmnopqrstuvwxyz-0123456789')"
AutoCompleteType="Disabled" Width="199px"></asp:TextBox><span style="color: Red">*</span>
<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtName"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revName" runat="server" ControlToValidate="txtName"
CssClass="text-error" Display="Dynamic" ValidationExpression="^[\p{L}\s]+$" ErrorMessage="Invalid Name"></asp:RegularExpressionValidator>
I also used the ValidationExpression ^[A-Za-z]+$ in order to test that whether there exist some error in the ValidationExpression, and then typed in Name in the textbox being validated and still it triggered the error message of the RegularExpressionValidator.
Regards
^[\p{L}\s]+$ would match 1 or more letters only(not digits) or space..
If you want to validate it with digits you have to use
^[\p{L}\p{N}\s]+$
This would match unicode letters,numbers and space 1 to many times

Possible to get the CompareValidator to accept numbers with commas?

I had been doing a type check for Double for an input field on a web page but now I need to allow commas. Can this be done using a CompareValidator or do I need to use a regex validator?
Rather than using Type="Double", try using Type="Currency". It should accept values with and without commas, however it will not accept more than 2 decimal places.
Here's an example:
<asp:TextBox runat="server" ID="TextBox1" />
<asp:CompareValidator runat="server" ID="cValidator" ControlToValidate="TextBox1"
Type="Currency" Operator="DataTypeCheck" EnableClientScript="true"
ErrorMessage="Invalid format!" Display="Dynamic" />
Otherwise a RegularExpressionValidator would work, coupled with a RequiredFieldValidator to validate empty entries (the regex validator doesn't prevent empty entries). You could use a CustomValidator, but you would need to come up with a client side validation routine in JavaScript if you don't want to rely solely on server side validation with a postback. Also, the client side solution may involve regex and it's more work to validate overall, although not too complicated.
This is an example using the RegularExpressionValidator:
<asp:TextBox runat="server" ID="TextBox1" />
<asp:RequiredFieldValidator runat="server" ID="rfValidator" Display="Dynamic"
ControlToValidate="TextBox1" ErrorMessage="Required!" />
<asp:RegularExpressionValidator ID="reValidator" runat="server"
ControlToValidate="TextBox1"
EnableClientScript="True"
ErrorMessage="Invalid Format!"
Display="Dynamic"
ValidationExpression="(\d{1,3}(,\d{3})*\.\d{2})|(\d+(\.\d{2})?)" />

ASP.NET 3.5 :No Postback triggered for button click

I have an ASP.NET page developed in VS 2008. there is a text box and login button.Required fireld validator and Validtion Group controls are associate for validation.I wrote code for the Button click evenet handler too.But the Button click is not getting fired.There is no post back happening. Can any one tell me why ?
HTM lmarkup
<asp:TextBox ID="txtLoginPass" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword" ValidationGroup="Login" ErrorMessage="Please enter password." runat="server" />
<asp:Button ID="btnLogin" runat="server" Text="Login"
onclick="btnLogin_Click" ValidationGroup="Login" />
Validators generate client side JavaScript which can prevent a postback if the required field is empty.
Is that exact code snippet? It didn't work at all - no such control as txtPassword.
Altough, this worked as expected:
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword" ValidationGroup="Login" ErrorMessage="Please enter password." runat="server" />
<asp:Button ID="btnLogin" runat="server" Text="Login"
onclick="btnLogin_Click" ValidationGroup="Login" />
I'm sure that you've got that correct in your code, so the problem must be somewhere else - could please post more code surrounding this snippet?
I expect that you have AutoPostBack="True" on one of your components. If so then remove that and your onclick should work on the button.
I had this same exact problem. The RequiredFieldValidator was working as expected when the textbox was empty, but the button click wasn't causing a postback when there was text. My problem? I was using the same validationgroup name in a separate user control. So make sure all of your validationgroup names are unique.

Resources