C# - RequiredFieldValidator Causes Validation On Server Even If Validator Is Disabled

Mar 28, 2011

I have a user control with a label and a field. I add the user control dynamically to a page at run time. There could be many user controls which are built dynamically from data I get from the data base. The data describes the label name and if the text box should be completed.. ie is it required. I have a submit on the main page which has a validation group.All the validators on the user controls have the same validation group. So far so good I hope.

The user control has a RequiredFieldValidator for the text box and looks all like this. The validator is enabled by default.

<asp:TextBox ID="dfControl" runat="server" Text="" ToolTip="ucsAlphanumericEntryDC" Width="95%" CausesValidation="true"/>
<asp:RequiredFieldValidator ID="rfvContol" runat="server" ErrorMessage="Value is required" EnableClientScript="true"
ValidationGroup="ValidateContols" ControlToValidate="dfControl" Display="Dynamic" Enabled="true"></asp:RequiredFieldValidator>

When I dynamically load the control I check a parameter to tell me if the field is required or not. The paramater is from the database which represents the control that I am about to draw. If the Field NOT a required field I disable the validation in the page_preRender.. also tried it in load.

if (!DisplayRequired)
{
rfvContol.EnableClientScript = false;
rfvContol.Enabled = false;
dfControl.CausesValidation = false;
}

So far so good. This all works on the client side validation for only the user controls with the Display Required set to true, leaving the Validator enabled.however on posting page from a submit button which I have wired to the same validation group as the user controls, I check the IsValid on the submit and if its false I dont save anything. But when the page re-renders on the client.. I have error messages on all the user controls, saying that they are required... even though I disabled some of them that where not required. the View state is default on the control which I assume to be on.

I also tried not redrawing the controls with the validators, by enclosing the code in a if(!IsPostBack)

why the validators fire when they are disabled on the first page load but dont get disabled on the postback.

View 1 Replies


Similar Messages:

Web Forms :: Validator Disabled On Client Still Validates On Server?

Jan 21, 2011

Here's one of the validators:

<asp:RequiredFieldValidator runat="server" ID="rfvCardNumber" ControlToValidate="txtCardNumber" Display="Dynamic" ErrorMessage="Credit card account number is required">*</asp:RequiredFieldValidator>

Here is the JavaScript/JQuery that I am using to disable this control:

ValidatorEnable($("#<%=rfvCardNumber.ClientID %>")[0],false);

This code does indeed disable the client side validation, but unfortunately it does not disable server side validation. I have a way to check to see if I need to validate them or not on the server but it's a bit complex and requires duplicating some code that is used later on to calculate the total due. I use that check and disable the validators in Page_Load and sure enough the validation does not occur. to get these validators disabled on the client & server from the client side?

View 3 Replies

Web Forms :: Textbox Server Validation If JavaScript Is Disabled?

Jul 30, 2010

I am trying to make ONE thing work. The form currently have TWO Textboxes and ONE CustomValidator(connected to the first textbox). I simply want once I enter less than 4 characters in the first Textbox and tab out to the second Textbox and if Javascript is DISABLED then the server side code should stop me. I can achieve what I am trying to do if I use a button but I need to do it in the fashion I am trying decribing because if I have for example 20 textboxes on the form I want the user to see after each data entry that his validation was successful or not. Here is a sample of my code.

[code]....

View 4 Replies

Web Forms :: Range Validator Fails Because The Textbox Is Disabled?

Feb 24, 2010

I have a couple of textboxes (actually a set of pairs of textboxes) where users can either enter a value or a percentage of a value but cannot use both. So in any given time some of these textboxes are disabled depending on which option the user chose.

For the textboxes representing percentages, there is a range validator to make sure only values from 0 to 100 are entered. If user selectes to enter datanot in percentage form, the percentage textbox gets filled automatically based on the value user enters. So if the total is something like 8 and user enters 2, the corresponding percentage textbox gets filled with 25% (minus the % sign).

However, the vaidation fails as if there is nothing there, persumably because the textbox is disabled. How do I get around this?

[code]...

View 2 Replies

Web Forms :: Disable A Validator That Associates With A Disabled Textbox?

Oct 21, 2010

If a control is disabled (enabled = false), will the validator controls associated with it automatically know not to carry out validation?i have a checkbox and a textbox, if the checkbox is checked, the textbox is enabled, and has to have a value, where i used a required field validator.but if the checkbox is not checked, textbox is then disabled, however, the validator controls still seem to be trying to validate the disabled textbox.so is there a way to disable validator according to textbox's state? such as textbox.enable = true? seems like causevalidation method requires multiple button, owever i only need one...

View 7 Replies

Implement A RequiredFieldValidator With A ValidationExpression Which Is Fail Validation?

Jun 8, 2010

I'm trying to implement a RequiredFieldValidator with a ValidationExpression which is fail validation if the value is -I'm guessing there will probably be a very simple RegEx for it but I am still trying to get my head around it.

View 7 Replies

Custom Server Controls :: Custom Validator Client-side Validation Cannot Work?

Jan 13, 2010

I've been trying to get a custom validator component working that ensures at least one checkbox from a checkboxlist has been checked. I've been used some code I found on dotnetjunkies.com but the client-side validation didn't work. I've been attempting to modify it to get the client-side javascript validation to work with no luck. Basically, I compile the below code into a DLL and add it to my bin folder.

[Code]....

View 2 Replies

Web Forms :: RequiredFieldValidator.RenderControl - Validation Firing On First Load?

Feb 5, 2011

I have today developed a page that builds a series of RadioButtonLists, which may or may not be required fields.

As the page varies depending on DB values, I have rendered the controls using .RenderControl().

Unfortunatley I do not have the code to hand right now, but its along the lines of:

RadioButtonList rblQuestion = new RadioButtonList();
rblQuestion.id = question.ID;
// Add ListItems...
RequiredFieldValidator rfvQuestion = new RequiredFieldValidator();
rfvQuestion.ControlToValidate = rblQuestion.ID;
rfvQuestion.ErrorMessage = "*";

I then use .RenderControl on both rblQuestion and rfvQuestion, concatenate into a string then use the HTML String to populate a PlaceHolder.

This seems to work fine, all appears as expected apart from the RequiredFieldValidator - I get a red asterix (My ErrorMessage) next to each RadioButtonList - But this appears as soon as the page loads, not on a post/button click.

View 6 Replies

Why Does DotNetNuke Have Validation Disabled

Feb 25, 2010

Can anyone shed some light on why DotNetNuke comes configured with request validation and event validation disabled? They're both off at the web.config level for a default install which seems to be a regressive approach. Are there any sound reasons for this and what is the functional impact on DotNetNuke if they're turned back on?

Obviously appropriate input validation should be happening in code anyway but the native .NET framework behaviour is always a nice fallback.

View 2 Replies

How To Use The Client-side Validation Of A RequiredFieldValidator In Combination With Custom Usercontrol

Apr 13, 2010

Using the ValidationProperty I've managed to connect a RequiredFieldValidator with my custom control. When I enable client script in the validator, JavaScript errors occur.

Is there a way to tell the RequiredFieldValidator how it can validate my custom control in the client?

View 1 Replies

C# - How To Handle Validation When JavaScript Is Disabled

Apr 4, 2011

I'm using some of the typical ASP.NET's Validation Controls in my website. Now I'm trying to disable the JavaScript in my browser to test my application and of course the Validation Controls no longer works. I think it's best to try to make them work using one of the solutions down here instead of reinvesting the wheel and build a validation layer for the page or my objects -Am I thinking right?-

What do you think of these options and why:

Include in clicked button's event a code to check if the page is valid and if not explicitly call the Page.Validate(); method Check if whether the JavaScript is enabled and if not I should call Page.Validate();

View 3 Replies

Web Forms :: When Any RequiredFieldValidator Validation Fails Display Generic Error Message To User

Aug 9, 2012

I use validation control in my page when users click on button if they don't enter data in textboxs it show massage in validation control

I want In addition to using validation control when users click on button to insert data  it show error massage thar show EX: "please complete your form"

How I can do it ?

View 1 Replies

Web Forms :: How To Work With Validation Controls If Javascript Disabled

Mar 24, 2011

if i turn off the java script in any browser will validation controls will work and if yes then how to work by disabling the java script

View 1 Replies

MVC :: Client Side Validation - Doesn't Disabled Elements

Jun 17, 2010

Using MicrosoftMvcValidation.js, it seems like disabled html elements are validated on the client-side. I am not sure how much sense that makes given that such elements will not be submitted by the form and I probably consider it a bug. (By the way, MicrosoftMvcJQueryValidation.js does not validate disabled elements.)

Is there any way I can disable (pun intended) the validation of disabled elements? E.g., assuming I have a reference to an html element in javascript, is there some way I can "remove" it or disable it from the client-side validation machinery?

View 6 Replies

Forms Data Controls :: Text Validator Case-sensitive / Change The Server-side validator?

Dec 13, 2010

I have a validator on a textbox that validates against a list to ensure that the user doesn't input the same name. When testing it, if I type in the same name including the same case structure, it returns an error. If I change one letter to a different case, it doesn't return an error but rather my SQL server returns a duplicate error. How do I change the server-side validator so that it picks up duplicate names regardless of case?

View 4 Replies

Dropdownlist Validation In Using Required Field Validator?

Mar 15, 2011

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.

[Code]....

View 1 Replies

Security :: Validation Does Not Perform On Requiredfield Validator?

Nov 4, 2010

I have inserted a login page using createuserwizard. but RequiredFieldValidator and CompareValidator does not perform at all and even all textboxes are blank, page is submitted and a record created in database

View 3 Replies

Web Forms :: Validation Controls: Required Field Validator

Mar 25, 2011

I'm trying to use a field validator to make sure one of my list boxes has a selection before the user is able to proceed to the next page. i'm having is that if the validation message is triggered, all of the buttons on my page loose functionality.Meaning, if I purposely trigger the validation control, I can't get rid of the error message and none of my buttons do anything when clicke after this.

The majority of the HTML:

[Code]....

Is there something that I need to add to the code behind of the page or the Java Script that I'm using?

View 1 Replies

Asp.net - Client Validation That Acts The Same As Page Validator/XSS Prevention?

Feb 9, 2011

I've got a free text form for people to submit feedback/support requests. ccasionally people will past in a support ticket or error log that contains something that triggers the .NET page validator as an XSS attempt. This takes the user to the error page as if the site choked on their input.Preferably, I'd rather have the page do some client-side validation when they press the save button before it's actually submitted.Is there a regex or some method I can hook into that would do the same basic check on the client side, or will I just have to write a regex that disallows certain characters all together like < and >?

View 1 Replies

Compare Validator - Validation Remains When Text Is Changed?

Jan 13, 2010

I have come unstuck with a simple compare validation.

I have the following code

<asp:TextBox ID="tbxHowMany" runat="server"
style="z-index: 1; left: 310px; top: 385px; position: absolute; text-align: center;"
Width="75px"></asp:TextBox>[code]....

So when a user enters a figure higher than 200, the validation appears.However, when I change this figure to say, 30, the validation remains. I must be doing something really stupid, I just don't know what!

UPDATE: I have also just noticed that this validation occurs when a number greater than '20' is entered into the checkbox. I'm not very confused. I am assuming this is a type issue?

View 1 Replies

Custom Validator Not Firing (No Error Message, But No Validation)

Jan 17, 2011

I have a custom validator:

<asp:CustomValidator ID="QuestionValidator" runat="server" ErrorMessage="Please select an option" ClientValidationFunction="QuestionValidator_ServerValidate" OnServerValidate="QuestionValidator_ServerValidate" ValidateEmptyText="true"></asp:CustomValidator>

[code]...

When I run the page, there is no validation and no error message. Please can you point out where I am going wrong, I'm suspicious it is at Page.Master.FindControl("form1").Controls.I have previously done such validation by looping through controls via form1.controls but this is unavailable as the page uses a form passed down via the master page.

View 4 Replies

ASP.NET: Custom Validation Not Working Even When Required Field Validator Is Used?

Jan 15, 2010

Here is a code for my web form control

<asp:TextBox runat="server" ID="txtUsername"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtUsername" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:CustomValidator OnServerValidate="checkUsername" ID="CustomValidator1" runat="server" ControlToValidate="txtUsername" EnableClientScript="true" ClientValidationFunction="checkUsername" ErrorMessage="CustomValidator"></asp:CustomValidator>

Client side validation
<script type="text/javascript">
function checkUsername(source,args){
alert("test");
/* alert(args.Value);

[Code]....

View 2 Replies

Web Forms :: Password Field Validation Using Custom Validator?

Jan 12, 2010

How can validate Password field using Custom validater control in asp.net 2.0 ?

View 1 Replies

JQuery Validation Plugin - Using Validator.addMethod In Loop?

Apr 29, 2010

I have a good number of regular expressions used for validation. Instead of manually typing in many addMethods for each regex, I tried using a loop. I have the below simulated struct to hold the regex name, RegExp object and validation message.

function RegExs(exprName, expr, exprVM) {
this.exprName = exprName;
this.expr = expr;
this.exprVM = exprVM;
}.......

View 1 Replies

Web Forms :: Required Field Validator & Validation Group?

Feb 12, 2010

I have a web forms where i have 10 required field validators for 10 textboxes. Validation group for these required field validator needs to be determined when the page loads. I tried to change the validator in the .cs file but failed.

rfvBT.ValidationGroup = "registration";

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved