Multiple ASP.NET validators - asp.net

I have an ASP.NET page with the following code.
<asp:TextBoxEx ID="CompSCEmail" MaxLength="100" runat="server"></asp:TextBoxEx> <asp:RegularExpressionValidator Display="Dynamic" ID="RegSubmitCompSCEmail" runat="Server" ControlToValidate ="CompSCEmail" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="(*)"></asp:RegularExpressionValidator>
<asp:ImageButton ID="SubmitButton" SkinID="submitButton" OnClick="SubmitButton_Click"
Action="Submit" ValidationGroup="submit" runat="server" VisibleOnRecall="false" />
<asp:ImageButton ID="SaveButton" SkinID="saveButton" OnClick="SaveButton_Click" Action="Save" runat="server" Visible="true" VisibleOnRecall="makerfirst" />
I want to validate the format of the email when the user click both "Submit" and "Save" button. Does anyone know how to do that?
Thank You.

Give your RegularExpressionValidator ValidationGroup Property.
On click of both of your Buttons call Page.Validate("yourvalidationgroup").
This way you can validate email on click of both the buttons.

Related

ValidatorCalloutExtender not working in Asp.net Ajax

I have a RadioButtonList with Yes and No Option.Upon clicking the Yes button,Textbox1 and TextBox2 will be displayed and clicking No button Textbox3 and Textbox4 will be displayed.All the above the textboxes have ValidatorCalloutExtender.Upon clicking the Submit Button, the ValidatorCalloutExtender is not popup.Can any please help me..
Here is the code sample:
<asp:RequiredFieldValidator ID="rfvENo" runat="server" ControlToValidate="txt1"
Display="None" ErrorMessage="Please Enter ENo!" ValidationGroup="Agent" />
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender10" runat="server" Enabled="True"
TargetControlID="rfvENo">
</cc1:ValidatorCalloutExtender>
Do you have the correct ValidationGroup="Agent" set on the submit button? Your code is working fine for me otherwise.
It requires a class to work
<asp:RequiredFieldValidator ID="rfvAddCubicFeet" runat="server" ControlToValidate="txtAddCubicFeet" Display="Dynamic" ErrorMessage='<br/>Enter the total cubic feet.' ValidationGroup="vgAdd" Enabled="False"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender9" runat="server" HighlightCssClass="validatorCalloutHighlight" TargetControlID="rfvAddCubicFeet"></cc1:ValidatorCalloutExtender>

Required Field Validator on FileUpload Control

I have a form in which I have two textboxes and one fileupload control, I am using required field validator on one textbox and on Fileupload control, When I am clicking the submit button, its disabling the fileupload control and not showing any validation for it.
I also have second button for Cancel, clicking on which redirects to previous page, when I am clicking this button its also disabling the fileuploadcontrol.
Below is my code
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:RequiredFieldValidator ID="rfvFileupload" ValidationGroup="validate" runat="server"
ControlToValidate="FileUpload1"></asp:RequiredFieldValidator>
<asp:TextBox ID="txtSubj" runat="server" ></asp:TextBox><asp:RequiredFieldValidator
ID="rfvSubject" ControlToValidate="txtSubj" runat="server" Display="Dynamic"
EnableClientScript="true" ErrorMessage="* required" ValidationGroup="validate" />
<asp:Button ID="btnupload" runat="server" Text="Send" ValidationGroup="validate"
OnClick="btnupload_Click">
<asp:Button ID="btncancel" runat="server" Text="Cancel" OnClick="btncancel_Click"
/>
Try using no ValidadationGroup:
<asp:FileUpload ID="fupDocument" runat="server" Width="100%" />
<asp:RequiredFieldValidator runat="server" Display="Dynamic" ErrorMessage="* Required Field" ControlToValidate="fupDocument">
</asp:RequiredFieldValidator>
I tried and work it.

ValidationGroup Not working with Custom Asp.NET control

I have a custom ASP.NET control that was created by inheriting from WebControls.ImageButton. In my markup I have the following
<td>
<CustomControlLibrary:CustomIcon ID="icnSave" CausesValidation="true" OnClick="DoSomething"
runat="server" Enabled="true" IconUse="Add" AutoSkin="true" SupportsEvents="true" ValidationGroup="ValidationGroupA" />
<asp:LinkButton ID="lbSave" OnClick="DoSomething" CausesValidation="true"
runat="server" ValidationGroup="ValidationGroupA">SAVE</asp:LinkButton>
</td>
When I click the "SAVE" link, the validation works as expected, however when I click on the CustomIcon, the validation does not work, and the DoSomething wired to the OnClick fires off.
Is there anything special that needs to be added to the custom controls to get ValidationGroups to work? Note: The CustomIcon control itself does not have any special validation that it does/
Sorry i don't know this line .
<CustomControlLibrary:CustomIcon ID="icnSave" CausesValidation="true" OnClick="DoSomething"
runat="server" Enabled="true" IconUse="Add" AutoSkin="true" SupportsEvents="true" ValidationGroup="ValidationGroupA" />
If you want to image button ,please try this sample
<asp:textbox id="tb1" runat=Server />
<asp:requiredfieldvalidator id="ReqField1" controltovalidate="tb1"
validationgroup="valGroup1" errormessage="Required" runat=Server />
<asp:ImageButton id="Button2" causesvalidation=true
validationgroup="valGroup2" ImageUrl="img.gif" runat=Server />
Demo

Button Click on Enter in asp.net

I have several panels in my page,and each panel has a submit and clearall buttons.
I am trying to set focus of enter to my submit button.
I have an image button in my logo,and everytime user hits enter,its downloading file on imageclick.
Can someone suggest how do i set focus of enter to my submit button.Any ideas?
<asp:Panel ID="Panel2" runat="server" Width="100%" ForeColor="Black" DefaultButton="btnSubmit">
<telerik:RadButton ID="btnSubmit" runat="server" TabIndex="1" OnClick="OnSubmitClick" CausesValidation="true" />
<telerik:RadButton ID="btnclearall" runat="server" OnClick="OnClearAllClick" CausesValidation="false" />
</asp:Panel>
try defaultfocus attribute in <form> tag ,
<form id="form1" runat="server" defaultfocus="btnSubmit" >
Have you tried the UseSubmitBehavior attribute?
<telerik:RadButton ID="btnSubmit" runat="server" TabIndex="1" OnClick="OnSubmitClick" CausesValidation="true" UseSubmitBehavior="true" />
Set the other buttons to false. Technically you shouldn't have to set UseSubmitBehavior to true since it is default but setting all others to false might help.

Disable an asp:RequiredFieldValidator if a checkbox is checked

I have 2 textboxes with required field validators, a button and a checkbox. When the check box is checked I want to disable the required field validator on the second textbox and allow the button to be clicked when the first textbox is completed.
This is generally what my aspx page looks like, although this is just a made up example:
<asp:RequiredFieldValidator ID="rfvName" ControlToValidate="Name" Display="Dynamic" ErrorMessage="Name Required" runat="server" />
Name: <asp:Textbox ID="Name" runat="server"/>
<asp:RequiredFieldValidator ID="rfvID" ControlToValidate="Name" Display="Dynamic" ErrorMessage="ID Required" runat="server" />
ID: <asp:Textbox ID="ID" runat="server"/>
<asp:Button ID="btn" Text="Query" runat="server"/>
<asp:CheckBox ID="chxNoID" Text="I don't have an ID yet" runat="server" />
use javascript. Get the checkbox change event & put the code below in function
var ctrl1 = document.getElementById('<%=rfvID.ClientID%>');
ValidatorEnable(ctrl1, false);

Resources