<asp:FileUpload ID="fuASNFile" runat="server" Width="480px"/>
<asp:CustomValidator ID="cvFileUpload" runat="server" ValidationGroup="Upload" ErrorMessage="Invalid value." ControlToValidate="fuASNFile" ClientValidationFunction="validateFile" Text="*" EnableClientScript="true"></asp:CustomValidator>
<asp:CustomValidator ID="cvFileUploadSave" ControlToValidate="fuASNFile" runat="server" ValidationGroup="Save" ClientValidationFunction="validateFileSave" ErrorMessage="Invalid File." Text="*" EnableClientScript="true"></asp:CustomValidator>
Only one of these two validation controls are working but not both.
Related
I have a RadMaskedTextBox for SSN while entering value in it, the first two characters are clearing up itself and getting RegularExpressionValidator message. Can some body help me in this.This problem exits in IE browsers only.
<span id="SSN" runat="server">*</span>Social Security Number</label>
<asp:RegularExpressionValidator ID="TaxId_RegEx"
runat="server" ControlToValidate="TaxId"
Display="None" ValidationExpression="^\d{3}\-\d{2}\-\d{4}$" ErrorMessage="Please enter a valid 9 digit SSN." Enabled="true"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="TaxId_ReqField"
runat="server" ControlToValidate="TaxId"
Display="None" ErrorMessage="Please enter a value for this required field."></asp:RequiredFieldValidator>
<radI:RadMaskedTextBox CssClass="box_SSN" SelectionOnFocus="SelectAll" ID="TaxId"
Width="85px" Mask="###-##-####" runat="server">
</radI:RadMaskedTextBox>
Try:
^\d{3}-\d{2}-\d{4}$
Instead of:
^\d{3}\-\d{2}\-\d{4}
This is working perfectly for me in IE:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1" Text="*">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ValidationExpression="\d{3}-\d{2}-\d{4}"
ControlToValidate="TextBox1"
ErrorMessage="Input valid SSN!">
</asp:RegularExpressionValidator>
<asp:Button ID="Button1" runat="server" Text="Submit"/>
Not sure why you have
Display="None"
I have search textbox,which has default value Enter Month to View Profit. When I click search button without entering any data, the default value of textbox is posted to server for search. I want that RegularExpressionValidator do not validate default value of textbox.
<asp:TextBox ID="Tboxsearch" Text="Enter Month to View Profit" OnClick="this.value=''" CssClass="textboxinput" runat="server"></asp:TextBox>
<asp:Button ID="ButtonSearch" CssClass="btnLog" runat="server" Text="Search" onclick="ButtonSearch_Click" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidatorname"
runat="server"
ControlToValidate="Tboxsearch"
ForeColor="Red"
Text="*"
>
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidatorname"
runat="server"
ValidationExpression="[a-zA-Z0-9]+"
ForeColor="Red"
ControlToValidate="Tboxsearch"
ErrorMessage="Enter Valid Name!"
>
</asp:RegularExpressionValidator>
The default for all validators except the RequiredFieldValidator control if you post with empty field the validator will not trigger
you must use required field validator with other validators to prevent the postback to happen
from MSDN
Special-Case Validation Results for ASP.NET Server Controls
EDIT
Also if you add your controls as in your question it should work but if there is other controls like for example other button you should set the validationGroup Property to the group that you want to work together
ValidationGroup="vGrp"
and your code will be like this
<asp:TextBox ID="Tboxsearch" Text="Enter Month to View Profit" OnClick="this.value=''" CssClass="textboxinput" runat="server" ValidationGroup="vGrp"></asp:TextBox>
<asp:Button ID="ButtonSearch" CssClass="btnLog" runat="server" Text="Search" onclick="ButtonSearch_Click" ValidationGroup="vGrp" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidatorname"
runat="server"
ControlToValidate="Tboxsearch"
ForeColor="Red"
Text="*"
ValidationGroup="vGrp">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidatorname"
runat="server"
ValidationExpression="[a-zA-Z0-9]+"
ForeColor="Red"
ControlToValidate="Tboxsearch"
ErrorMessage="Enter Valid Name!" ValidationGroup="vGrp"></asp:RegularExpressionValidator>
from MSDN about validationGroup
I have 2 buttons which validates different sets of textboxes (which have corresponding asp validators). How can I control the validations triggered by each button?
Add ValidationGroup="set1" and ValidationGroup="set2" properties to your textboxes, buttons, Validators and Validation Summaries, that should do it.
You have to set the same Group name for each set of textbox and buttons .
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="GroupOne"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="ErrorMessageForTextBox1" ValidationGroup="GroupOne">
</asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="GroupOne" />
<asp:TextBox ID="TextBox2" runat="server" ValidationGroup="GroupTwo"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2"
ErrorMessage="ErrorMessageForTextBox1" ValidationGroup="GroupTwo">
</asp:RequiredFieldValidator>
For ASP version 1.1 , use this link !
I have a textbox txtemailid which has two validator RequiredFieldValidator and RegularExpressionValidator as:
<asp:TextBox ID="txtEMailId" CssClass="Text1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RFVtxtEMailId"
runat="server"
ErrorMessage="*"
Display="Dynamic"
ForeColor="Red"
ControlToValidate="txtEMailId"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="REVtxtEMailId"
runat="server"
ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
Display="Dynamic"
ErrorMessage="Invalid Email Format"
ForeColor="Red"></asp:RegularExpressionValidator>
it shows following error
The ControlToValidate property of 'REVtxtEMailId' cannot be blank.
You not have specified which control should be validated .Try this
<asp:RegularExpressionValidator ID="REVtxtEMailId"
runat="server"
ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
Display="Dynamic"
ErrorMessage="Invalid Email Format"
ForeColor="Red" ControlToValidate="txtEMailId"></asp:RegularExpressionValidator>
You have not provided ControlTo Validate Property in Regular Expression Validator.Add this property in REVtxtEMailId
here is my code:
<asp:ValidationSummary ShowSummary="true" ID="ValidationSummary1" ValidationGroup="x" runat="server" />
<asp:RequiredFieldValidator ValidationGroup="x" ControlToValidate="ddlIso" ID="RequiredFieldValidator2" runat="server" Display="none" SetFocusOnError="true" ErrorMessage="<br>y is required"/>
<asp:RequiredFieldValidator ValidationGroup="x" ControlToValidate="txtIsoAct" ID="RequiredFieldValidator3" runat="server" Display="none" SetFocusOnError="true" ErrorMessage="<br>y Base Activity is required"/>
<asp:RequiredFieldValidator ValidationGroup="x" ControlToValidate="txtIsoDate" ID="RequiredFieldValidator4" runat="server" Display="none" SetFocusOnError="true" ErrorMessage="<br>y Base Activity Date is required"/>
Validation Summarys hows all three messages on one line... how can i get them to show up as bullets?
Use the DisplayMode property:
http://msdn.microsoft.com/en-us/library/dd5c6s6h%28v=vs.71%29.aspx