views:

341

answers:

1

I want to show a modal dialog/pop-up window when the user has not filled in a text field on the page, instead of using an error text field on the page.

If the required text field is filled in, I want the submit button to work as normal (aka call the onClick function), but if it's not filled in, I want a dialogue window/modal pop-up to show up stating that they need to fill in the specific field.

What's the best way of this?

I personally prefer using the jquery ui library over the ajax control toolkit modal popup if possible.

+2  A: 

All that you have to do is to do the following.

  1. Create a JS function that does the validation, display the dialog if it errors. Have that function return true/false if validation is ok or fails.
  2. On your button, add an "onClick" method to the attributes. "javascript: return YourFunction();" and you should be set to go.

The return value of your method will prevent postback if returning false!

Mitchel Sellers
Did you mean onClientClick? How do I call the backend submit function after the js validation?
stringo0
no, just do myButton.Attributes.Add("OnClick", "myjshere"). It will automatically do the postback as long as your function returns true.
Mitchel Sellers
WOW! Thanks - didn't know that.
stringo0