0

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.

1
  • I think a way of intercepting a button click and performing js before the postback is what I'm looking for - user clicks button, js determines whether to cancel the normal functioning (the onclick function) or not. Commented Sep 1, 2009 at 15:21

1 Answer 1

2

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Did you mean onClientClick? How do I call the backend submit function after the js validation?
no, just do myButton.Attributes.Add("OnClick", "myjshere"). It will automatically do the postback as long as your function returns true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.