Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12376

Validating controls in an UpdatePanel with a button outside the UpdatePanel

I have two UpdatePanels in my form, both containing several DropDownLists and TextBoxes, most of which need to be validated. I have a validation summary and validators grouped together in a separate div. The div is not inside either of the update panels. And I finally have a button that isn't either in any UpdatePanels. How can I make sure that by just clicking button I get all my controls validated and shown in the validation summary?

Upvotes: 0

Views: 2779

Answers (2)

DavRob60
DavRob60

Reputation: 3557

First, your button must be set as a AsyncPostBackTrigger of both UpdatePanels.
Secondly, you must set EnableClientScript="true" to all your Validators, this will perform the validation on the Client side (java script).
Finally, your button's ValidationGroup must match the one of your Validators.

However, if you need to perform some validation on the server side, you must put your Validators in update panel to update them asynchronously.

Upvotes: 1

Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12376

Believe me I achieved this without doing any of these suggestions. I just set validation group of my button and all the validators to the same value. That's it.Let me remind you the case: I have a two updatepanels.Validators of the controls on the first panel are in a seperate div, which is not contained in either of the panels. The second update panel has only one control to validate so I've put its validator to the same panel. And I have a button that's completely apart from all these. When I click the buton I can get all the validation messages summarized in the validationsummary. However a very strange thing still remains a secret: As I said validators of the first panel controls are outside that panel and they work pretty well. But if I take the only validator from the second update panel and put it among the other validators I don't get that single validator's message. I'm almost sure that this is a bug in Visual Studio as I've witnessed many things like this.

Upvotes: 0

Related Questions