views:

1859

answers:

4

I need a technique for dealing with what seems pretty simple!

I have a form, with some logic on the server side for validation. if the server side code indicates that there is an issue, I want to display a modal popup to the client.

I am having trouble getting it to work in this way.

I found if I keep all the logic client side, I can use the javascript function

window.showModalDialog("url","title", "style");

However the logic is currently on the server side. this is an ASP.NET 3.5 web project - is there some way to do this using AJAX controls like the scriptmanager, an update panel etc?

Thank you!

A: 

You need to use an AJAX callback to perform your server side validation and return a response to the client - then decide whether to display the modal dialog... however, why do you need to validate on the server? It is usually best to try and validate in the client to save roundtrips...

flesh
It's possible that he's validating both client side (for speed) and server side (for security). I'm not sure for this specific case, but it's a reason why one would do server side validation.
ahockley
Or, needs server side if javascript is turned off. But wait, then the modal dialog wouldn't work either. Nevermind.
JasonS
yeah but he actually says 'I found if I keep all the logic client side, I can use the javascript function' - I know there are reasons why you might validate server side but there's no suggestion in the post why he needs to...
flesh
+1  A: 

Beware that modal dialogs are not supported in all browsers.

You may be able to accomplish something similar using DHTML and setting the visibility of divs from the server side if your server side validation fails.

You might also look at Telerik's RadWindow control which was designed (in part) to solve the modal dialog problem.

JasonS
+2  A: 

I know that you do it using the ScriptManager control. Basically you just send from the server a line of JavaScript to execute immediately. In this case, the client side line you describe.

Sorry to be vague, but it's almost quitting time and I'll have to grep through a lot of code to find an example.

Here is an example

CMPalmer
A: 

You really shouldn't use the modal popuper. First of all it mstly works only in IE. Second of all it's REALLY annoying for your end users...

You should rather use something like e.g. this;Ra-Ajax Clendar Starter-Kit (click the "Create New Activity" in the bottom left corner)

Thomas Hansen