<asp:ValidationSummary ID="vsArea" runat="server" />
<div class="controls">
<asp:DropDownList ID="ddlDegreeLevel" runat="server"
placeholder="DegreeLevel" CssClass="form-control">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvDegreeLevel" runat="server"
ControlToValidate="ddlDegreeLevel"
Display="None" ForeColor="Red" InitialValue="-1"
ErrorMessage="Please select degree level" Text="">
</asp:RequiredFieldValidator>
</div>
Errormessage of "rfvDegreeLevel" is show on validation-Summary and also below the control. I also set Display="None" but still show on both area .
I want to show message only on Validation summary.
This is by design...message will be shown in validation control and in the summary. Basically you have 2 options
Show separate messages in your control and validation summary. E.g. you can put a red * in the validation control and detailed error message in the summary, which is a best practice. To achieve this, set both Text and ErrorMessage property of the validation control. Text will be appearing in the control and ErrorMessage will be appearing in the summary.
hide the message from control, set the Display property of the control to none..
You have to add validationgroup to all the controls. For this you can use the following code:
<asp:ValidationSummary ID="vsArea" runat="server" ValidationGroup="degree" />
<div class="controls">
<asp:DropDownList ID="ddlDegreeLevel" runat="server"
placeholder="DegreeLevel" CssClass="form-control">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvDegreeLevel" runat="server"
ValidationGroup="degree"
ControlToValidate="ddlDegreeLevel"
Display="None" ForeColor="Red" InitialValue="-1"
ErrorMessage="Please select degree level" Text="">
</asp:RequiredFieldValidator>
</div>
Related
I have spent hours on this and read countless threads but not sure what i may be missing to get this to work the way i would like.
I would like to select a file to upload and when the user clicks the button to save the record if there are any validation errors to retain the value of file that was selected to upload.
Heres my markup
<asp:MultiView runat="server" ID="RegisterMultiView">
<asp:View ID="DefaultView" runat="server">
<asp:UpdatePanel ID="upCountryBrands" runat="server">
<ContentTemplate>
Select parent
<asp:RequiredFieldValidator
SetFocusOnError="true"
runat="server" ID="RequiredFieldValidator3"
ControlToValidate="ddlParent" InitialValue="0"
ValidationGroup="MainForm" ErrorMessage="Please select"
Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlParent" runat="server"
OnSelectedIndexChanged="ddlParent_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
Select Child
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ID="RequiredFieldValidator2"
ControlToValidate="ddlChild" InitialValue="0"
ValidationGroup="MainForm" ErrorMessage="Please select"
Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlChild" runat="server"
OnSelectedIndexChanged="ddlChild_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
Name
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ID="RequiredFieldValidator1"
ControlToValidate="txtName" ValidationGroup="MainForm" ErrorMessage="Please enter your name" Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:TextBox ID="txtName" runat="server" MaxLength="100" />
Enter description of your issue
<asp:TextBox ID="txtIssue" runat="server" TextMode="MultiLine" /> <%--This is a Tiny MCE control--%>
Image 1
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ID="rfv1" ControlToValidate="FileUpload1" ValidationGroup="MainForm"
ErrorMessage="Please select an image." Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revFileTypes" runat="server" ErrorMessage="Images only." ControlToValidate="FileUpload1" ValidationExpression=".*\.(gif|jpe?g|png)$"></asp:RegularExpressionValidator>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="false" accept="image/*" ViewStateMode="Enabled" EnableViewState="true" />
<asp:Label ID="lblImageOneStatus" runat="server"></asp:Label>
Image 2
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ID="RequiredFieldValidator9"
ControlToValidate="FileUpload2" ValidationGroup="MainForm" ErrorMessage="Images only" Display="Dynamic">Required</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Images only." ControlToValidate="FileUpload2" ValidationExpression=".*\.(gif|jpe?g|png)$"></asp:RegularExpressionValidator>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="false" class="form-control-file" accept="image/*" />
<asp:Button ID="btnSave" runat="server" Text="Save" ValidationGroup="MainForm" OnClick="btnSave_Click" OnClientClick="txtIssue.triggerSave(false,true);" />
</asp:View>
<asp:View ID="SuccessView" runat="server">
Thanks
</asp:View>
</asp:MultiView>
Couple of notes:
I have an updatePanel surrounding the dropdown so it looks like theres no postback.
I have tried surrounding the FileUpload controls with an UpdatePanel but this made no difference.
I have a TonyMCE control, i dont think this would add a spanner into the works but i have left out the associated Javascript so i can provide if required.
I have tried adding triggers but again this made no difference so i can only assume i am doing something wrong.
How could i ensure when a file is selected using the FileUpload controls and then press Save it retains the value of the file?
In am using htm required="required" validation but it is not working properly as needed.
I have 2 button on single page and I want that on 1 button click it validate for textbox1 and on click of 2nd button it will validate for textbox2.
Please review attached image for more detail
You are looking for ValidationGroup. By giving a collection of Validators and a Button the same id, the corresponding button will only validate those fields.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1" ValidationGroup="group1"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox2" ValidationGroup="group1"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button Group 1" ValidationGroup="group1" />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox3" ValidationGroup="group2"></asp:RequiredFieldValidator>
<asp:Button ID="Button2" runat="server" Text="Button Group 2" ValidationGroup="group2" />
I don't think HTML does that natively (grouped validation).
If server-side is not an option, then you'll need to use some JavaScript.
I have found some inspiration in this answer for a related question (Triggering HTML5 Form Validation) : https://stackoverflow.com/a/39689115/370786
If you group each set of inputs that you want to validate together in a form (so you will have several forms), then you can trigger validation through Javascript. Then you can stop the form from posting. This can be done through Javascript - maybe it can be done in HTML but I'm not sure.
Then once everything has validated you will need to post the data to the server, using some Javascript. It might be as simple as just triggering the submit() method on a form element.
I have a question. I have a textarea and 2 textboxes. What I want to do is to check if textarea is filled, other 2 textboxes must not be empty. We can give messagebox like this (please necessary fields must be filled)
This is my code :
<textarea id="txtCustomerRepresentatorOpinion" name="txtCustomerRepresentatorOpinion" runat="server" style="width: 99%"></textarea>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="txtCustomerRepresentatorOpinion"
ValidationGroup="Save" Text="*" ClientValidationFunction="txtArea" />
<telerik:RadTextBox Width="321px" runat="server" ID="txtCustomerRepresentatorOpinionNameSurname" TextMode="SingleLine" />
<asp:RequiredFieldValidator ID="VldAdi" runat="server" ControlToValidate="txtCustomerRepresentatorOpinionNameSurname"
ValidationGroup="Save" Text="*" ErrorMessage="Lütfen Adı Soyadı giriniz."/>
<telerik:RadDatePicker ID="rdpCustomerRepresentatorOpinionDate" ZIndex="9999" Style="vertical-align: middle;" runat="server">
</telerik:RadDatePicker>
<asp:RequiredFieldValidator ID="VldTarih" runat="server" ControlToValidate="rdpCustomerRepresentatorOpinionDate"
ValidationGroup="Save" Text="*" ErrorMessage="Lütfen Tarihi giriniz.">
</asp:RequiredFieldValidator>
Which side should I use (client side or server side)? How i do this job? Right now, I can show messages but textarea is not working.
Change your textarea into an asp.net TextBox Control with TextMode="MultiLine". Then a RequiredFieldValidator will work.
<asp:TextBox ID="txtCustomerRepresentatorOpinion" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required field" ControlToValidate="txtCustomerRepresentatorOpinion"></asp:RequiredFieldValidator>
I've done some searching around and seem to be the only one with this sort of issue. I have a few asp:RequiredFieldValidator on my form and basically what happens is that when the validation is tripped, only a red asterisk shows up and not my error message.
Here is the validator:
<asp:RequiredFieldValidator runat="server" CssClass="label label-danger"
ControlToValidate="email" ErrorMessage="Please provide an email address."
Display="Dynamic" SetFocusOnError="true" Text="Please provide an email address." />
And here is the control being validated:
<asp:TextBox runat="server" CssClass="form-control" ID="email" placeholder="First.Last" ClientIDMode="Static" TabIndex="1"></asp:TextBox><span class="input-group-addon">#ourdomain.com</span>
All of this is inside a master page and an update panel.
To show only the asterisk instead of Error Message type the asterisk into the tag
<asp:RequiredFieldValidator runat="server" CssClass="label label-danger"
ControlToValidate="email" ErrorMessage="Please provide an email address."
Display="Dynamic" SetFocusOnError="true" Text="Please provide an email address.">*</asp:RequiredFieldValidator>
The span will display * on the validator and the validator summary will show the complete message
I have a textbox and I have set required validationcontrol on it on click of a button.
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" runat="server" ControlToValidate="name" ErrorMessage="Name is required" Display="Dynamic" />
</td>
but the problem is when I am clicking on modify shared webpart and when I click on APPLY or OK button it is not saving as my form is empty . and I can't put
CausesValidation="false" on that button as this button is by default in sharepoint.
Any idea how to resolve this...?
You can use the ValidationGroup property to group all the Validators and validation fields together.
Yes using the ValidationGroup tag will help to relate the controls in a single form and will tell the submit button which fields are associated. Also make sure you have a ValidationSummary control on the page with the same ValidationGroup value. Also consider adding an InitialValue="" onto the TextBox control.
<asp:ValidationSummary ID="vs1" ShowMessageBox="true" ShowSummary="false" DisplayMode="List" runat="server" ValidationGroup="Form" HeaderText="There were problems with your submission:" />
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" ValidationGroup="Form" runat="server" ControlToValidate="name" InitialValue="" ErrorMessage="Name is required" Display="Dynamic" />
<asp:LinkButton ID="lnkSubmit" Text="Submit" OnClick="lnkSubmit_Click" ValidationGroup="Form" runat="server"></asp:LinkButton>