method of validating a large group of textboxes - asp.net

I have a bunch of text fields on my form that I need to submit to an object.
Before I submit, I first check to make sure the textbox is not empty.
I have about 40 text fields in my form, and I need to do this for 30 of them.
I have to do this 30 times to the various text fields:
If Not String.IsNullOrEmpty(textboxBookTitle.Text) Then Book.DisplayName = textboxBookTitle.Text
Is there a way to group the 30 text fields into some type of array so that I can process them via a loop rather than check each one individually?
Thanks

Why not use a asp:requirefieldvalidator?
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx
This could check that the textboxes have a value on clientside before being submitted to the server.
Just put all the textboxes on the same ValidationGroup as the validator and the button.

Related

asp.net webform Repeater, Update a set of textbox, Add to the List / Array

I am working on old webform asp.net application which uses Repeater.
The Repeater is a set of Name and address textbox fields. I have 3 sets of Name and Address information, basically, 3 sets of records in the object list to bind.
On the UI, I changed/update one of the Name and Address. I noticed in the list, which it iterate or loops through the repeater control
foreach (RepeaterItem item in this.NameAddressRepeaterControl.Items)
I see that an extra recod is added to the items.
Question:
I am used to fixed textboxes. When I update the textbox, I write code to take Exactly what is filled in the textbox and populate the DTO object to pass to the data layer to perform database transaction to update the database records.
When the new updated record is added to the Repeater Control list, I don't know which records is updated and which is the new records.
I am checking out OnItemDataBound and OnItemCommand to see if there is a way to get the old value from one of the field and also record the value of the new value. Is this possible?
The form contains 1 Save button and it will loop through the Repeater.Items to see what Name/Address to extract, but the new and old company exist in this list.
Instead of looping through the RepeaterControl.Items, Is there a way to extract from directly the visible Repeater control? If there are 3 repeater Name/Address control, is there a way to get all the info from each of the 3 sets of Repeater controls? The Repeater wraps around a user control, NameAddressCtrl.
I prefer not to replace the Repeater controls with fixed textboxes.
Any help is greatly appreciated.
Thanks.
I reviewed the code several time and add additional code to keep track what was add and changed in the repeated and only passed the information to be saved to the db. The solution was to write additional code. I did not change anything with the repeater behavior. Thanks for the comments and help.

Drupal node needs submit, edit and submit again to fill all data

I have a Drupal node form with fields that depend on each other.
First field takes data (using default value and tokens) from other fields
Second field takes data from the first field
The problem is, that on hitting "save", only first field shows data. To fill second field, I need to hit "edit" and than "save" again.
Is there a way to fill both fields on one "save"?
Will appreciate any guidance.

Contact Form 7 - press button to validate fieldset

I've used Contact form 7 (wordpress plugin) to create a single form with multiple fieldsets.
The fieldsets are then split (using jquery) like this: http://thecodeplayer.com/walkthrough/jquery-multi-step-form-with-progress-bar
What I want to do is validate all the fields in the fieldset (without submitting the form) - is there a way to
1) validate fields using the validation in contact form 7 manually?
2) specify which fields to validate (based on only those in a fieldset)?
Ideally I want to be able to do it with flexibility in mind as I will be creating 2 or 3 other forms that perform the same way.
Edit: by validate I mean check that the field is:
a) filled in, if it's a required field
b) valid data (so making sure its an email address etc).
My problem is I want to validate the fields manually, without submitting the form, so I can stop them progressing on to the next step of form filling if they've not completed the current fieldset of fields correctly.
Carl
What you want to validate ?
If you want to validate an email address. You should write input type = email in your email textbox.
HTML will validate textbox itself, that it should be in email format.
Same as for digits. If you want to validate that a textbox should contain only number.
Use input type = number on your textbox.
Here is an Example:
https://jsfiddle.net/z9b5mcur/1/

ASP.NET: How to validate a number input and format it with thousand separator on fly?

On ASP.Net form, I have a couple input fields which only integer allowed and maximum is 8 digital. right after entering value to the textbox field, it will check the validation. after passing the validation, it will format it with thousand separator. all these happen on fly.
I use Regular Express to do the validation. for example: Regex="^-?\d+{0,8}$".
My question is: I can use this regex to check the input and format it with thousand separator, but when hit save button, it fails on validation(Page.IsValid) because the textbox value will show number with commas(,).
For example: since the field only takes integer,when user enter 20000, it pass regex check at first, but after it format with 20,000 it fails the validation.
So how can I make this work? Thanks.
You can try custom validator
How to: Validate with a Custom Function for ASP.NET Server Controls

DynamicPopulate with multiple triggers

I want to dynamically populate a form field from multiple other fields in the form.
If input A or input B is changed, input C should be updated based on the values in input A and input B.
The DynamicPopulateExtender in Ajax control toolkit has almost this. With it I can populate a target based on a trigger.
Solved with jQuery...

Resources