开发者

Using server side validators with modal dialog (jquery)?

开发者 https://www.devze.com 2023-01-28 18:54 出处:网络
Is there a straightforward way to use server-side validation with ASP.NET\'s validation controls in a form that\'s displayed in a modal dialog? I am using jQuery and SimpleModal (in C#, VS2010, .NET 4

Is there a straightforward way to use server-side validation with ASP.NET's validation controls in a form that's displayed in a modal dialog? I am using jQuery and SimpleModal (in C#, VS2010, .NET 4.0)

I've got a modal form which works fine. I need to use a server-side validation because the logic depends on data specific to the record being accessed

My solution for the project I'm working on now is to use a jQuery ajax call to pass all the form data to the server and get back the validation results before allowing the post to proceed. But this is relatively time consuming to implement, and in some situations I'm dealing with now all the validation code exists already.

The first challenge is that of course the modal dialog will close on a full postback. So you could put an UpdatePanel inside the dialog... without even thinking开发者_开发百科 about this too much, though, I assumed that it wouldn't work out that well. It doesn't. And the form which opens the modal dialog to begin with is already in an UpdatePanel, which further confuses matters.

Anyway, I tried putting the contents of the modal form in an UpdatePanel for the heck of it. It does actually do a partial postback, the dialog remains open, but the contents of the dialog do not get updated with anything I change server side. If I close and re-open the dialog on the same page after testing the validation code, though, its contents are in fact updated to reflect these changes. Obviously the way the dialog is rendered is confusing ASP.NET. Or vice-versa. But this just seems sketchy from the get-go.

Rather than trying to hack my way through this problem I was hoping that others had some suggestions about a better way to approach this. Or just tell me I'm trying to hard too mix apples and oranges and I should keep it all client side (or client side + jQuery ajax) if that is the only sensible thing to do.


The two approaches I've taken:

1) submit the data via ajax, the response includes a success:true or false. If false, there is a message included that details the issue.

2) submit the form normally. If there is a validation problem, but the errors in a hidden div on the page and write JS to check for content in that div when the page loads and display the warning/error as necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消