I have calendarextender for a textbox. I need do the requiredfiled validation after lost focus. But the code below doesn't show red * after lost focus.
<asp:TextBox ID="txtDateS" runat="server" Width="80px"/>
<cc1:calendarextender ID="ceDateS" runat="server" CssClass="cal" Enabled="True" TargetControlID="txtDateS" />
<asp:RequiredFieldValidator ID="rfvDates" runat="server" ErrorMessage="RequiredFieldValidator" Text="*" ControlToValidate="txtDateS"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="rfvDates_ValidatorCalloutExtender" runat="server" Enabled="True" TargetControlID="rfvDates"></cc1:ValidatorCalloutExtender>
The RequiredFieldValidator doesn't fire when the control loses focus (unless you've previously entered text and then removed it), what you can try is to add the following to the page load event:
txtDateS.Attributes.Add("onblur", "ValidatorOnChange(event);")
Related
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>
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
I have a lot of textboxes on submit page and all have a validator. I want to control them with a submit button which is on master page. It works but other buttons also cause validation. validation summary is always shown either submit button is clicked or any other buttons. how can I control this situation? (asp.net)
for each individual submit use "ValidationGroup". here is the sample:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="TextBox1" ValidationGroup="Submit" ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="TextBox2" ValidationGroup="Submit" ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" ValidationGroup="Submit" runat="server" Text="Button" />
I think you can resolve this by using ValidationGroup Property..
http://msdn.microsoft.com/en-us/library/ms227424.aspx
http://www.w3schools.com/aspnet/prop_webcontrol_imagebutton_validationgroup.asp
Thanks
Deepu
After validation failed, I have a problem with controls (dropdownlist or button) that should cause a new postback. I will try to explain it clearly...
The purpose of my page is to save fives dates in a database. The page has the following controls:
Five textboxes, each one containing a date
A reset button (CausesValidation=false) to restore a default date in one of the 5 textboxes
A dropdown list (AutoPostback=true, CausesValidation=false) of predefined templates that applies 5 dates to the 5 textboxes
A button to save the dates to the database
The textboxes can be edited manually. So, when I click the Save button, if the format of the dates is not valid, the validation fails and the save is aborted. The problem is just after that. If I click on the Reset button or select an item in the dropdownlist, the postback is not triggered. If I try again, then it works. Is there a way to make it work the first time after the first validation failed? I tried deactivating the validation on the client-side when changing the selection in the dropdownlist but the postback still does not occur.
Here is the relevant part of the code:
<asp:DropDownList ID="cboScheduleTemplates" runat="server" AutoPostBack="true" CausesValidation="false" />
<asp:TextBox ID="txtDateDelivery1" runat="server" />
<asp:RegularExpressionValidator ID="revDateDelivery1" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery1" Text="*" />
<asp:TextBox ID="txtDateYearbookQuantity" runat="server" />
<asp:RegularExpressionValidator ID="revDateYearbookQuantity" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateYearbookQuantity" Text="*" />
<asp:TextBox ID="txtDateDelivery2" runat="server" />
<asp:RegularExpressionValidator ID="revDateDelivery2" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery2" Text="*" />
<asp:TextBox ID="txtDatePersonalizations" runat="server" />
<asp:RegularExpressionValidator ID="revDatePersonalizations" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDatePersonalizations" Text="*" />
<asp:TextBox ID="txtDateDelivery3" runat="server" />
<asp:Button ID="btnSetDefaultDelivery3" runat="server" ValidationGroup="Schedule" CausesValidation="false" />
<asp:RegularExpressionValidator ID="revDateDelivery3" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery3" Text="*" />
<asp:Button ID="btnSaveSchedule" runat="server" CssClass="btnAction" Text="Save" ValidationGroup="Schedule" />
<asp:ValidationSummary ID="validationSummarySchedule" runat="server" ValidationGroup="Schedule" DisplayMode="List" />
As suggested in this post, the problem comes from calls to Page_ClientValidate. So I wrapped the client function like this and the problem went away:
function DoPageClientValidate(validationGroupName)
{
var result = Page_ClientValidate(validationGroupName);
Page_BlockSubmit = false;
return result;
}
I have a dropdown list on my aspx page on which I have a RequiredFieldValidator applied over it. DropDown code is:
<asp:DropDownList ID="ddlglCategoryId" runat="server" CssClass="textEntry2"
AutoPostBack="true" ValidationGroup="Save" DataSourceID="dtsglCategoryId" DataTextField="LookupItem"
DataValueField="Id" AppendDataBoundItems="true">
<asp:ListItem Text="All" Selected="True" Value="0"></asp:ListItem>
</asp:DropDownList>
RequiredFieldValidator code is:
<asp:RequiredFieldValidator ID="rfvddlglCategoryId" InitialValue="0" runat="server"
ErrorMessage="Please select category" CssClass="Validations" ControlToValidate="ddlglCategoryId"
ValidationGroup="Save" Display="Dynamic" SetFocusOnError="true">
</asp:RequiredFieldValidator>
I have a post back trigger as well on my aspx page and when I change the category from the dropdown, page posts back and a grid on my page gets updated. But due to post back, the validator message appears and then disappears. I want this to appear only when "All" is selected from dropdown and user clicks save button.
Any guidelines?
Trigger:
</ContentTemplate>
<Triggers>
<%--<asp:AsyncPostBackTrigger ControlID="lbFileName" />--%>
<asp:PostBackTrigger ControlID="btnFileUploadSave" />
</Triggers>
</asp:UpdatePanel>
Button:
<asp:ImageButton ID="btnFileUploadSave" runat="server" ValidationGroup="Save"
ImageUrl="~/App_Themes/Default/images/update.png" ToolTip="Save"
Height="18px" onclick="btnFileUploadSave_Click"/>
You may need to set the AutoPostBack property of the dropdownlist to false. It sounds like a postback is getting fired with the OnSelectedIndexChanged event handler.
Set the ValidationGroup Property Of all Validaters same which you want to validate on button click and then set buttons ValidationGroup property same as Your Validators
For Example:
<asp:RequiredFieldValidator ID="rfvDoc" runat="server" ControlToValidate="FileUpload1"
ErrorMessage="Please Select A Document" ValidationGroup="OnSave">
</asp:RequiredFieldValidator>