.net validators + client-side javascript validation, EnableEventValidation=false

Scenario:

1. I have a DropDownList, with 2 listitems in the .aspx. appenddatabound=true and it is tied to a datasource (via datasourceid), autopostback=false, onchange=checkIfAddNew(this) [this is the client side onchange event]
The second option on this dropdown is "Add New", and the checkIfAddNew function pops up a new window and when it returns, it adds the newly created option to the dropdown. In order for this to happen without asp.net getting mad, EnableEventValidation has to be set to false in the Page directive. In addition to this dropdownlist, there is a RequiredFieldValidator tied to it.

2. I have a table where rows are dynamically added by the client (all client-side javascript) via 'add row' buttons. Each row can contain a few fields (input type=text) whose type may be general text or numerically based.

3. asp:button on the form, which serves as the 'submit' button. However once they hit this button, I need to validate the data created by #2, then submit the form.

Problem One:

In #1, even though I have enableeventvalidation disabled,  if the option I submit the form with was a newly created option, asp.net doesn't think the page is valid based on the requiredfieldvalidator returning false for the dropdownlist it's tied to. Is there a correct way to use .net validators on DropdownLists who's value at submission may be one that .net doesn't expect?

 

Problem Two:

The asp:button's (save button) onClientClick is set to: "return validateRows()", however, this completely overrides the client-side validation that .net creates. So how can I correctly validate my dynamic form stuff, then have .net validate the stuff it needs to, and then submit the form? I don't want to manually call:

WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("btnSave", "", true, "", "", false, false))

in my javascript validation function!

Any suggestions?

0
debo
1/13/2007 10:19:50 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

1 Replies
1213 Views

Similar Articles

[PageSpeed] 21

Anybody?
0
debo
1/15/2007 1:35:02 AM
Reply:

Similar Artilces:

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

validating .net validation controls using javascript
 I need to validate multiple .net validation groups(a normal group would consist of RequiredFieldValidators, RegularExpressionValidators, ValidationSummary, etc) using javascript.  I am using Page_ClientValidate("GroupName") to validate the groups.  The problem arises when i validate multiple groups.  The validation summary and errors only appear for the last group validated or nothing appears if the last group validated returns true.  I want all validation summaries and errors to appear for all groups that return a false validation.  I'll never va...

Client validation using both Javascript and .NET controls
 Hello,I have implemented an online questionnaire. The questionnaire is composed by several textboxes to gather information such as name, organization,email, phone, etc. and a long series of radiobuttonlists and textboxes (text area). These last textboxes need to be filled out only if the user select a specific value in the radiobuttonlists.To perform client validation I used .NET controls to check the format of the first textboxes (name, organization,email, phone, etc. ) and the text areas to ensure that no invalid characters have been entered.To check the all the radiobuttonlist has b...

Server side validation affecting client side validation
Hi there I have some client side validation that is working fine and enables/disables buttons based on user selections. This works great. However, when I perform server side validation using custom validators (like checking if the user has entered < HTML > tags or decimals in the integer boxes) and the server side validation returns isValid = false then all of the JavaScript validation that I've already done when the user clicked each control is lost. I don't understand why the enabled/disabled state of the control is not maintained.  What is calling the JavaScr...

client side validation vs server side validation
hello  i see a web form that consists of three controls :textbox,requiredfieldvalidator that weired to the textbox and a button within the click event of the button there is the following: if page.isvalid then response.redirect("Page is valid") else response.redirect("Page is not valid") end if according to my understandings: when the user does not fill anything in the textbox and then clicks the button the the page will not be submitted (i.e no request to the page will be happened or no postback will be happened) then no server event will be happened so it is sure when the user submits the page so it will be valid so why the developer checks if the page is valid or not? so i need to understand this topic if any wrong in my understandings tell me please because i need to understand this concept thank you for the help That is slightly wrong. Unfortuantely the answer is not easy.For ASP.NET 1.0 and 1.1The javascript that is put onto the page to check its validity is only compatible with IE. This means that if you are using, e.g firefox, the javascript would not be put onto the page. The page would then postback even if the textbox was empty.If you were using IE, then the page would not postback.For ASP.NET 2.0The javascript that is put onto the page to check its validity is meant to comform to the W3C standards, so should work on every browser. This means that no postback will occur.For good web developingNo matter what happens, you should always do serve...

Server Side Validation vs Client Side Validation
If your page is using client side validation for required fields, expressions, etc.     What are the benefits or disadvantages of using 'extra' server side validation for max lengths, parsing, etc? Both have their Advantages and Disadvantages... so give this a read http://www.dotnetexpertsforum.com/viewtopic.php?t=172 Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET hi there, advantage: because you are using javascript some browsers for any reason may not sup...

avoiding redundant server-side validation after client-side validation
I see an inaccurate validation behavior on my asp.net (2.0) form. The EnableClientScript property of my validation control is set to True by default, so it performs the validation on clientside. But as soon as this occurs, it also performs the server-side validation, so the page refreshes. When the validation error occurs on clientside, it should not do the validation on serverside (I'm not calling Page.Validate() or doing Page.IsValid). In my past experience, asp.net handled this automatically, but I guess it's not always the ca...

Highlighting web form fields on validation error events (client-side)
Have anybody eventualy did that? This is a nice feature when the web form highlights it's input fields and/or lables for that fields if they are not validated (client-side). Unfortunatly, there is no such build-in functionality in ASP.NET 2.0 validation controls. But i'm quite sure that's it's possible to make on your own, what do you think?Perhaps an additional js script shoud be added on the buttom of the page which will redefine one or more functions of original js code.Any comments, thoughts, suggestions?My LinkedIn Profile - ASP.NET C# Ninja | My News Feeds Turned out that it's quite ...

validation, is it better to have client side or use server side validator controls
 Hi All. I want to do validation on text boxes etc. Is it better to do client side validation or just use the server side validation controls?   Hi!  If for server side controls you mean RequiredFieldValidator, CompareValidator, RegularExpressionValidator, etc.. i can tell you that they use client and server validation. For instance if you use a RequiredFieldValidator, on the client will be a validation, but on the server this condition will be evaluated again. Probably one of the objetives of this is deal with client with javascript disabled. Of course I ...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

validation controls
Hi all,I have a web form with a few controls and reqdfield, compare & regex validation controls. On all validation controls i have enabled the client script property. Yet when I submit the form it does a postback to do the validation. Any ideas? I am running vs2005 beta 2.TIA! Hello.how do these validators perform the validation of the other controlos? whar browser are you using?-- Regards,Luis Abreuemail: labreu_at_gmail.comEN blog:http://msmvps.com/blogs/luisabreu Well they are regular requiredfield, regex & compare validators. Browser is latest version of Firefox. I had to use...

custom validator and client side validation
Hi, Am I creating a new custom validator class derived from BaseValidator. I am NOT writing code in aspx page itself.I have successfully written the class file, created the dll and server side code works great. Now, how do I write the client side validation code for the same validation?Should I use this procedure http://aspnet.4guysfromrolla.com/articles/073102-1.aspx and write the code in seperate .js file? (This code is for inline custom validator not a separate class of validator)OR is there a procedure to write the javascript code inside my CustomValid...

Custom Validator: How to validate on Client Side
Hi, I'm using custom validator to validate a custom control. I've defined "ValidationAttribute" to a property called "HiddenValue" and i want to validate the control against this value. It was working fine on the server side. However, on the client side it is not validating as expected. The value property of arguments is some thing holding some other value. How can we pass the "ValidationAttributes" value to this? Is there any other workaround for this issue? Regards, Anand   ValidationAttribute is a server side concept. When writing your client-side evaluation function, you h...

.net validation vs custom validation
Hello, Coming from a background of Classic ASP. I have a logic of validation which also does out security and account. Basically, we use a stored proceedure to validate and then also log success, failures, attempts etc Can this be done using .net validation or i have to build my own validation logic ? And how is this done ? thanks Ehi You can use Custom validator control Using the CustomValidator Control  Hosam Kamel Remember to click on Mark as answer on the post that helped you...

form double validation- server side and client side
Hi! I would like to make a server side validation after calling a js function that makes the client-side validation. I do not understand couple of things: 1. Do i need a server side button or  a simple HTML submit button in order to call both of the tests? 2. How do i call a server side function which is written in csharp  after i finish my JS validation (the submit  button is calling the JS function for validation first.)- is it possible to call it directly from a js function? 3. I know that my toolbox on asp.net  contains validation controls who probably are b...

Client Side Validation For Custom Controls / Validators
Hi there people, I'm creating my own set of self validating text boxes. They all inherit from a base text box which simply contains a required field validator, they then usuallly implement another validator to check they contain number, currencies, dates or whatever. The problem i'm having is with the DateTextBox, I have created my own Date Validator which inherits from the BaseValidator class which the DateTextBox uses. My problem is that no validation is taking place on the client side. I've included the code for all related parts, if you need anymore info then please just let me k...

custom validator, client-side validation infraestructure
Hi, I have been implementing a custom validator that uses the ASP.NET validator infraestructure, by deriving from CustomValidator. It is a custom TextBox which renders and registers a custom validator and also attaches a client-side behavior to the textbox. The problem is that the ASP.NET validator infraestructure uses a <span> element to hold the validator configuration (validation function, control to validate, etc.) and renders it inside a <script> tag in a RegisterExpandoAttribute fashion : var MyValidator1 = document.all ? document.all["MyValidator1"] : doc...

How to force client-side validation with a custom validator
Hello, I am using a custom validator to validate a hiddenfield.  The server side validation works fine.  when the page is validated it checks to ensure that the hiddenfield has an appropriate value.  However, I am now trying to get clientside validation to work with the custom validator.  Because the validator is validating a hidden field, I cannot set the hiddenfield in the ControlToValidate property.  Is there a way to force client-side validation of a custom validator in javascript?  For instance, when the hidden field is populated, it calls a functio...

custom validator and validation summary
I have created a custom validator that checks that an item has been selected in a dropdownlist. The serverside validation works great, but I am having trouble getting the clientside to work correctly. I have my validationsummary set to show a messagebox, but this is not happening. Can anyone help me.     function isJobDDLSelected(sender, args)     {         alert('here');         var returnBoolean = true;         var ddlJob = document.getElementById("ddlJob") &...

client validation of validators
when you have validators across your page, is there a way to validate that they all passed on the client side? similar to Page.IsValid on the server. Reason being, I need to do some client side processing when all validations pass.Alvin ShihSoftware DeveloperMCP MCTS MCPD You might be able to do this by overriding the client-side validation functions that are auto-generated by ASP.NET.  If you look at the source HTML for a page with validators on, you should see JavaScript functions such as ValidatorOnSubmit() and ValidatorCommonOnSubmit().  If you add some more script after these are defined on the page e.g. immediately before the closing HTML body tag, you may be able to do what you require: (function() { var oldFunc = (ValidatorOnSubmit.constructor == Function) ? ValidatorOnSubmit : null; if (oldFunc) { ValidatorOnSubmit = function() { // run the old validation function and store the result var result = oldFunc(); // do your custom processing here var myResult = myProcessing(); return (result && myResult); } } })(); Please mark helpful posts as "Answer" In your javascript code, call Page_ClientValidate('validation group name'). It returns true if the validation group is validate and false if not. Generally when it returns false, you also return false so that the event that called your code (onclick or form.onsubmit) wi...

dot net validation + javascript
Hi         Can we check the success of dot net validation in javascript ThanksHingole Sachin Hi zcon_sachin@hotmail.com Yes we can, and the following information is from MSDN article ASP.NET Validation in Depth, it is really a good article which talks about this topic:   The Client-Side API There is a mini-API that you can use on the client to achieve various effects with your own client-side code. Because it is not possible to make certain routines hidden, you can theoretically make use of any of the variables, attributes, and functions d...

Javascript client side validation
Hi,   I have a main page ,and inside the page there is ascx usercontrol  which has inside it some textbox .the ascx gets loaded into the main page on menu click.inside the ascx's textbox some validation required and this validation should happen only when a button in the main page is clicked. validations -textbox can't be left balnk like this. so i have to call the function of validation from  button's onclick event in main page where i cannot pass the control as parameter .now how to get the control's id inside my javascript validation function.     &nbs...

Client Side Form validation
OK - I agree ASP.net validator controls are way kool. But I don't think they COMPLETELY replace the need for good old-fashioned hand-coded JavaScript client side form level validation. For example, say I have a form with 10 textboxes indicating possible percentage amounts for various elections in a 401K retirement account. The amounts need to add up to 100%, but only 1 box must be filled in, although all ten could be filled in. Thus we do not have a simple must enter scenario, and only with the click of the submit button can we validate that all the numbers do add up to 100%. I see no...

Server Side Validation in .NET
I have an ASP.NET app that has server side validation. This app needs to run in IE and Netscape. The validation(required field validators) does not work at all in Netscape. I have my Target Schema set to IE and Netscape. Any help or advice on this is much appreciated? Do I have to rewrite my validation in Javascript? My project goes live in 2 days. C...