requiredfieldvalidator

how to make requiredfieldvalidator error message display after click submit button

前提是你 提交于 2019-11-29 07:17:42
now, the error message will display if I move out of current textbox. I don't want to display it until I click submit button. This isn't possible when ClientScript is enabled for your validators. And the ClientScript is by default enabled for your validators. You need to disable this by settings EnableClientScript to False in your source. Now in the event handler of your submit button call Page.Validate() and Page.IsValid to see if every validators did pass the test. Example: <asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ControlToValidate="txtFirstName" EnableClientScript="false

Bypass HTML “required” attribute when submitting [duplicate]

孤人 提交于 2019-11-29 06:20:40
问题 This question already has answers here : Required attribute HTML5 (7 answers) Closed 6 years ago . I use required for a 1st check before submitting a form. <form action="myform.php"> Foo: <input type="text" name="someField" required="required"> <input type="submit" value="submit"> <input type="submit" value="ignore"> </form> Problem is, that I have an "ignore" button, which submits the form as well and the backend logic then sets a correct state in a DB. In this case (ignore) the validation

RequiredFieldValidator have to click twice

左心房为你撑大大i 提交于 2019-11-29 05:13:47
I have run into the same problem as described here . Only the question is marked as answered with only an explanation as to why you may have to click twice when using a RequiredFieldValidator on input fields - once as the blur of a textbox(for example) will correct the validation and then again to actually post the form. I don't want to have to click a button twice! Does anyone know a solution or workaround to this? You could add EnableClientScript=false to the validator. That prevents the client-side validation, so you will always get a postback (which may not exactly be what you want, though

Dropdownlist validation in Asp.net Using Required field validator

陌路散爱 提交于 2019-11-29 01:40:16
问题 I have Dropdownlist whose value field and text field are bind at runtime. it has --select-- as first item with a value of 0 and the rest of the values are bind at runtime. I have given validaton group for both the control and the validator as "g1" and Intialvalue=0 But still the page is posting back even if I select --select-- option. <asp:DropDownList AutoPostBack="true" CssClass="dropdown" ValidationGroup="g1" ID="ddlReportType" runat="server" OnSelectedIndexChanged="ddlReportType

Conditionally required property using data annotations

血红的双手。 提交于 2019-11-28 16:38:53
I have a class like this: public class Document { public int DocumentType{get;set;} [Required] public string Name{get;set;} [Required] public string Name2{get;set;} } Now if I put a [Required] data annotation on the Name and Name2 properties, then everything is ok and if Name or Name2 are empty, validation will throw an error. But I want Name field only to be required if DocumentType is equal to 1 and Name2 only required if DocumentType is equal to 2 . public class Document { public int DocumentType{get;set;} [Required(Expression<Func<object, bool>>)] public string Name{get;set;} [Required

Enable/Disable asp:validators using jquery

北慕城南 提交于 2019-11-28 07:41:19
I am working with a wizard, where the user can sign up. There is a asp:RadioButtonList with two options, and some of the input fields in the wizard changes when the radiobutton changes. On each field there is some asp:Validators (asp:RequiredFieldValidator for example). The problem is, that when the user submits the page, the validator for the hidden textbox is still popping up. First, here is the div tags which changes the shown textboxes and the RadioButtonList <div id="divTxt1"> <asp:TextBox runat="server" CssClass="text" ID="txtNumber" type="number"/> <asp:RequiredFieldValidator ID=

Dynamically enable or disable RequiredFieldValidator based on value of DropDownList

坚强是说给别人听的谎言 提交于 2019-11-28 05:43:56
I have an ASP.NET form with three text inputs, one each for "Work Phone", "Home Phone" and "Cell Phone". Each of these text inputs has a RequiredFieldValidator associated with it. I also have a DropDownList where the user can select the preferred phone type. I want to only require the field that is selected in the DropDownList. For example, if the user selects "Work Phone" from the DropDownList, I want to disable the RequiredFieldValidator for "Home Phone" and "Cell Phone", thereby only making the "Work Phone" field required. I have a method that enables and disables these validators based on

Enable/Disable asp:validators using jquery

牧云@^-^@ 提交于 2019-11-27 01:55:19
问题 I am working with a wizard, where the user can sign up. There is a asp:RadioButtonList with two options, and some of the input fields in the wizard changes when the radiobutton changes. On each field there is some asp:Validators (asp:RequiredFieldValidator for example). The problem is, that when the user submits the page, the validator for the hidden textbox is still popping up. First, here is the div tags which changes the shown textboxes and the RadioButtonList <div id="divTxt1"> <asp

Dynamically enable or disable RequiredFieldValidator based on value of DropDownList

夙愿已清 提交于 2019-11-27 01:02:10
问题 I have an ASP.NET form with three text inputs, one each for "Work Phone", "Home Phone" and "Cell Phone". Each of these text inputs has a RequiredFieldValidator associated with it. I also have a DropDownList where the user can select the preferred phone type. I want to only require the field that is selected in the DropDownList. For example, if the user selects "Work Phone" from the DropDownList, I want to disable the RequiredFieldValidator for "Home Phone" and "Cell Phone", thereby only

How to add a RequiredFieldValidator to DropDownList control?

会有一股神秘感。 提交于 2019-11-27 00:39:39
I have a DropDownList binded with a SqlDataSource to display the values from the database. I am unable to validate using a RequiredFieldValidator . For the most part you treat it as if you are validating any other kind of control but use the InitialValue property of the required field validator. <asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="your-dropdownlist" InitialValue="Please select" ErrorMessage="Please select something" /> Basically what it's saying is that validation will succeed if any other value than the 1 set in InitialValue is selected in the dropdownlist.