SkyeBoniwell
SkyeBoniwell

Reputation: 7102

method of validating a large group of textboxes

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

Upvotes: 0

Views: 52

Answers (1)

NicoTek
NicoTek

Reputation: 1167

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.

Upvotes: 2

Related Questions