views:

31

answers:

2

Hi,

I have a form in a MS AJAX ModalPopup Extender, which is in a UpdatePanel (for async loading). Everything works as expected. There is one thing that I am trying to do but not sure how to do it.

On form submission, there is server side validation on top of client side validation. My question is: what is the best way to display validation error messages if any? It would be ideal if the messages could be written to the popup asynchronously so that the popup is still there.

If this is not possible, I am thinking of displaying the messages using the JavaScript alert box.

Any insight and suggestions are greatly appreciated.

John

+2  A: 

It's been awhile since I have used the ModalExtender and UpdatePanels but this is possible. Essentially (rust falling out of head), I had a label inside of the modal set to visible=false. Then, on clicking the Ok button, I called a function in the code behind that processed the logic. If the logic failed, then I updated the label text and set visible = true. If the logic passed, I called the close() property of the modal. With both, you have to call updatePanel.update() so that the content is refreshed. Let me see if I can find an example...

Not Exactly what I was looking for, but it may help you get on the right track:

If (logInstance.isNew) Then
    result = logInstance.createNewLogEntry()
    If (result.ToLower = "success") Then
        Response.Redirect("default.aspx?status=1")
    Else
        saveErrorType.InnerHtml = result
        ModalSaveError.Show()
    End If
Else
    result = logInstance.updatePreviousLogEntry(textReasons.Value)
    If (result.ToLower = "success") Then
        Response.Redirect("default.aspx?status=2")
    Else
        saveErrorType.InnerHtml = result
        ModalSaveError.Show()
    End If
End If
Tommy
+1  A: 

Tommy, thanks for the reply. Instead of replying to you as a comment, I am doing it as an answer, hoping that somebody can tell me if this is the best we can do. Also it may be of some help to those who face the same situation.

After posting yesterday I spent a couple more hours on it and found a solution, which is basically the same idea as you described in your answer.

The key issue was that I am not using the OK button of the extender. Instead I used a regular linkbutton which triggers a server side click event when clicked. This event closes the popup regardless of the validation result. So my goals was to keep the popup open or at least make it appear to be open and then add whatever validation error message to it.

After I cleared my thought on the issue, I figured I should be able to re-open the popup and populate the form with the data that the user is working on, and adding my validation error messages to it.

That did it!

Thanks again.

John
Anytime! I looked at my .aspx page code and had done the same thing - No OKBtnID parameters on those modals.
Tommy