Last post Apr 27, 2012 07:41 AM by nijhawan.saurabh
Apr 27, 2012 03:07 AM|namratapednekar|LINK
I have a page with various text fields dropdowns with required field validator and custom validator. Some fields are shown dynamically on index change so are the validator.
problem is when button property causes validation is set to true the onclick event of button is not triggered, but if set to false it is done.
Thanks for the help
Apr 27, 2012 03:16 AM|nijhawan.saurabh|LINK
You can set the ValidationGroup property of all controls which take part into validation as one validationgroup.
Apr 27, 2012 03:17 AM|karthicks|LINK
hi, as you have mentioned that you are using some required field validator and custom validator , if anu of the validation fails then button onclick will not fire.
if you want to fire button event irrespective of validation controls then set button's CausesValidation="false"
or else to do partial valdation you can set ValdiationGroup
Apr 27, 2012 04:47 AM|namratapednekar|LINK
tried both the solution but still no success.
Apr 27, 2012 05:07 AM|nijhawan.saurabh|LINK
Did you set ValidationGroup property for dynamically generated controls as well?
If not, do that as well and give another ValidationGroup to the Button which is causing the problem.
Apr 27, 2012 05:08 AM|namratapednekar|LINK
I have assigined validation group for specific control and check the same is working fine.
But some textboxes are displayed on indexchange method of dropdown. This controls are not validated onclick event.
Apr 27, 2012 05:11 AM|nijhawan.saurabh|LINK
I didnt get you on this point.
If you dont want a postback on selection of a item in dropdownlist, use autopostback=false.
Apr 27, 2012 05:14 AM|namratapednekar|LINK
i have wrote code in codebehind for onSelectedIndexChanged so i have to use AutoPostBack=true
<asp:DropDownList ID="ddlpurpose1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlpurpose1_SelectedIndexChanged">
<asp:ListItem Value="Others">Others Please Specify</asp:ListItem>
<asp:RequiredFieldValidator runat="server" ID="rfvpurpose1" ControlToValidate="ddlpurpose1" ErrorMessage="Please select Purpose" InitialValue="Select" ValidationGroup="val_cpf"></asp:RequiredFieldValidator> <br />
<asp:TextBox ID="txtacc_purpose1" runat="server" Visible="false" ValidationGroup="acc_purp1"></asp:TextBox><br />
<asp:CustomValidator ID="cvtxt_purpose1" ValidateEmptyText="true" ControlToValidate="txtacc_purpose1" runat="server" Display="Dynamic" ValidationGroup="acc_purp1" ErrorMessage="Enter purpose of opening account" Text="Enter purpose of opening account" ClientValidationFunction="Validate"></asp:CustomValidator>
cs file code:
protected void ddlpurpose1_SelectedIndexChanged(object sender, EventArgs e)
if (ddlpurpose1.SelectedValue == "Others")
txtacc_purpose1.Visible = true;
cvtxt_purpose1.ErrorMessage = "Enter purpose of opening account";
txtacc_purpose1.Text = "";
txtacc_purpose1.Visible = false;
cvtxt_purpose1.ErrorMessage = "";
Apr 27, 2012 05:21 AM|nijhawan.saurabh|LINK
Code is fine now what is not working?
Apr 27, 2012 05:40 AM|namratapednekar|LINK
as per the code the dropdown is validated on button click.
but on page load text box visibility is false, it is visible only if "other" is selected from dropdown.
so if the textbox is visible it is no validated on button click.
Apr 27, 2012 06:49 AM|namratapednekar|LINK
hey the issue is resolved by setting SetFocusOnError="true" property of custom validator
Apr 27, 2012 07:41 AM|nijhawan.saurabh|LINK