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
Related
<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.
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 hvae a textbox and image button.upon clicking image button , the calendarextender will appear and the selected date from calendarextender should be populated in the textbox.but date is not populated.please guide me to fix this issue.
Here is my code
<asp:TextBox ID="txtAccidentDate" MaxLength="10" Text=""
runat="server" SkinID="ClaimTextBox" Width="80px" TabIndex="1" />
<cc1:MaskedEditExtender ID="MaskedEditExtender2" runat="server"
TargetControlID="txtAccidentDate" Mask="99/99/9999"
MessageValidatorTip="false" MaskType="Date"
DisplayMoney="Left" AcceptNegative="Left"
ErrorTooltipEnabled="True" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="txtAccidentDate"
Display="None"
ErrorMessage="Please select Accident Date"
ValidationGroup="Insured" SetFocusOnError="true">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="txtAccidentDate"
ValidationGroup="Insured" Display="None"
ErrorMessage="Please Enter valid Date"
SetFocusOnError="true"
ValidationExpression="(((0?[1-9]|1[012])[/.](0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])[/.](29|30)|(0?[13578]|1[02])/31)[/.](19|[2-9]\d)\d{2}|0?2[/.]29[/.]((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))">
</asp:RegularExpressionValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender5"
runat="server" Enabled="True"
TargetControlID="RegularExpressionValidator2">
</cc1:ValidatorCalloutExtender>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender6"
runat="server" Enabled="True"
TargetControlID="RequiredFieldValidator1">
</cc1:ValidatorCalloutExtender>
<cc1:CalendarExtender ID="CalendarExtender2"
runat="server" Enabled="True"
PopupButtonID="imgcal" Format="MM/dd/yyyy"
TargetControlID="txtAccidentDate" />
<asp:ImageButton ID="imgcal" runat="server" CausesValidation="false"
ImageUrl="~/Images/Calendar_scheduleHS.png" />
<span class="helpInformantion">(mm/dd/yyyy)</span>
I think you have used ScriptManager right. Just use ToolScriptManager Instead of ScriptManager
i.e.,
Change This
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
to
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
Try this code
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:TextBox ID="txtAccidentDate" MaxLength="10" Text="" runat="server" SkinID="ClaimTextBox" Width="80px" TabIndex="1" />
<asp:MaskedEditExtender ID="MaskedEditExtender2" runat="server" TargetControlID="txtAccidentDate"
Mask="99/99/9999" MessageValidatorTip="false" MaskType="Date" DisplayMoney="Left" AcceptNegative="Left" ErrorTooltipEnabled="True" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtAccidentDate"
Display="None" ErrorMessage="Please select Accident Date" ValidationGroup="Insured"
SetFocusOnError="true">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtAccidentDate"
ValidationGroup="Insured" Display="None" ErrorMessage="Please Enter valid Date"
SetFocusOnError="true" ValidationExpression="(((0?[1-9]|1[012])[/.](0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])[/.](29|30)|(0?[13578]|1[02])/31)[/.](19|[2-9]\d)\d{2}|0?2[/.]29[/.]((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))">
</asp:RegularExpressionValidator>
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender5" runat="server" Enabled="True"
TargetControlID="RegularExpressionValidator1">
</asp:ValidatorCalloutExtender>
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender6" runat="server" Enabled="True"
TargetControlID="RequiredFieldValidator1">
</asp:ValidatorCalloutExtender>
<asp:CalendarExtender ID="CalendarExtender2" runat="server" Enabled="True" PopupButtonID="imgcal"
format="MM/dd/yyyy" TargetControlID="txtAccidentDate" />
<asp:ImageButton ID="imgcal" runat="server" CausesValidation="false" ImageUrl="~/Images/Calendar.png" />
<span class="helpInformantion">(mm/dd/yyyy)</span>
You have to write the code to set the of selected calender date to text box.
you can do this by writing code on calender's SelectionChanged Event
Your code should look like
protected void calendarextender_SelectionChanged(object sender, EventArgs e)
{
txtAccidentDate.text = calendarextender.SelectedDate;
}
Here calender extender is the id of your extender.
I am using 4 required field validators,4 regular expression validators and 4 compare validators for 4 text boxes.Is it possible to show error messages
in an alert or message box when validation fails?
If possible please send code sample.
Regards,
NSJ
<form id="form1" runat="server">
<asp:Label ID="lblNameRequired" runat="server" Text="*Name :"></asp:Label>
<asp:TextBox ID="txtNameRequired" runat="server" ValidationGroup="Validation"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="txtNameRequired"
Display="None" ErrorMessage="Name is Required" ValidationGroup="Validation"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="lblGenderRequired" runat="server" Text="*Gender :"></asp:Label>
<asp:DropDownList ID="ddlGenderRequired" runat="server" ValidationGroup="Validation">
<asp:ListItem Selected="True" Value="-1">--Select--</asp:ListItem>
<asp:ListItem Value="0">Male</asp:ListItem>
<asp:ListItem Value="1">Female</asp:ListItem>
</asp:DropDownList>
<asp:CompareValidator ID="CompareValidatorGender" runat="server" ControlToValidate="ddlGenderRequired"
Display="None" ErrorMessage="Gender is Required" Operator="NotEqual" ValidationGroup="Validation"
ValueToCompare="-1"></asp:CompareValidator>
<br />
<asp:Label ID="lblValidation" runat="server" Text="Fields marked with * are required"></asp:Label>
<br />
<asp:Button ID="btnValidate" runat="server" Text="Validate Input" ValidationGroup="Validation" />
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" ValidationGroup="Validation" />
</form>
You should use the same ValidationGroup text on all validation controls and add a ValidationSummary with the ValidationGroup and ShowMessageBox="true"
Use the following code , just set the correct messeges that u want :
<asp:ValidationSummary ID="ValidationSummary1" ShowMessageBox ="true"
runat="server" />
<asp:textbox id="txt1" runat="server"></asp:textbox>
<asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server"
controltovalidate="txt1" errormessage="Please Enter Only Numbers" validationexpression="^[-+]?\d+(\.\d+)?$">
</asp:regularexpressionvalidator>
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="txt1"
errormessage="please enter txt1">*</asp:requiredfieldvalidator>
<asp:textbox id="txt2" runat="server"></asp:textbox>
<asp:regularexpressionvalidator id="RegularExpressionValidator2" runat="server"
controltovalidate="txt2" errormessage="Please Enter Only Charcters" validationexpression="^[a-zA-Z\s.]*$">
</asp:regularexpressionvalidator>
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="txt2"
errormessage="please enter txt2">*</asp:requiredfieldvalidator>
<asp:textbox id="txt3" runat="server"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="txt3"
errormessage="please enter txt3">*</asp:requiredfieldvalidator>
<asp:Button ID="btnok" runat="server" Text="ok"/>
Don't do it. Users hate alert box error messages. It is a horrible UI design. Put the error messages on the form where the user can read them and they stay while the user makes changes or moves on without having to click on an alert box. Especially when there are multiple corrections to be made, they need to be able to read the errors while they make the corrections.
You can use this function
set parameters validation message and Control ID as parameters
protected void PopupMessage(string Msg, Control controlID)
{
ScriptManager.RegisterClientScriptBlock(controlID, controlID.GetType(), "msg", "alert('" + Msg + "');", true);
}
within the button click event you can this function according to your logic
protected void btnok_Click(object sender, EventArgs e)
{
if(TextBox1.Text=="")
PopupMessage("Name is Required", btnok);
}
please follow following code which is useful for me use ShowSummary property to reduce duplication of message into your pannel
<asp:ValidationSummary ID="VS1" ShowMessageBox="true" runat="server" ShowSummary="False" />
<asp:Label ID="lblUsername" runat="server" >User name</asp:Label>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RFV1" runat="server" ControlToValidate="txtUserName" ErrorMessage="Please Select Name" Display="None" SetFocusOnError="True">
</asp:RequiredFieldValidator><br />
<asp:TextBox ID="Textboxtotalamount"
OnTextChanged="AmountChanged"
Width="90px"
AutoPostBack="true"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator"
runat="server"
ControlToValidate="Textboxtotalamount"
SetFocusOnError="True"
ValidationGroup="val">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="Textboxtotalamount"
ValidationExpression="^[-+]?[1-9]\d{0,13}(\.\d{1,3})?%?$"
SetFocusOnError="True">F</asp:RegularExpressionValidator>
in this above code can validate correctly.......but in text box i call "OnTextChanged"
event ....suppose if i type(characters)in textbox errormesge shown at the same time ontextchanged event also called hen error occured ....i ve to stop OnTextChanged event when regularexpression raised......
pls help
try this
<asp:TextBox ID="Textboxtotalamount" OnTextChanged="AmountChanged" Width="90px" AutoPostBack="true"
CausesValidation="true" ValidationGroup="val" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ControlToValidate="Textboxtotalamount"
SetFocusOnError="True" ValidationGroup="val">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="Textboxtotalamount" ValidationGroup="val"
ValidationExpression="^[-+]?[1-9]\d{0,13}(\.\d{1,3})?%?$" SetFocusOnError="True">F</asp:RegularExpressionValidator>
i've added. the CausesValidation="true" and ValidationGroup="val" to the TextBox.
and ValidationGroup="val" to the RegularExpressionValidator
now the OnTextChanged will only fire when all the validators in the group "val" succeed