Showing posts with label validators. Show all posts
Showing posts with label validators. Show all posts

Monday, March 26, 2012

Modal popup only if validators pass

Hi. I would like my required field validators to be enforced prior to opening the modal popup. What is the best approach?

Thanks,
Brian

In the latest release of the Toolkit the modalpopup sample page demonstrates how to show and hide the modal popup programmatically. You candownload the source code from here and check out the sample website(the Toolkit sample website is not live yet so it will not show the new page). In the click handlers of the buttons that show/hide the modal popup you can add clauses to show it in only when certain conditions are met.

// Add click handlers for buttons to show and hide modal popup on pageLoad function pageLoad() { $addHandler($get("showModalPopupClientButton"),'click', showModalPopupViaClient); $addHandler($get("hideModalPopupViaClientButton"),'click', hideModalPopupViaClient); } function showModalPopupViaClient(ev) { ev.preventDefault(); var modalPopupBehavior = $find('programmaticModalPopupBehavior'); modalPopupBehavior.show(); } function hideModalPopupViaClient(ev) { ev.preventDefault(); var modalPopupBehavior = $find('programmaticModalPopupBehavior'); modalPopupBehavior.hide(); }

Saturday, March 24, 2012

Modal Popup Validation

I have 2 required field validators in an update panel in my modal popup panel. I use Matt Gibson's Validator dll and tag mapping for validators inside update panels. However, in this modal popup, postback is not prevented. As you can see, I give the modal popup no control over the save button. Yes, the validation group is the same on the validators and the button. Yes, the validation appears onblur. With the errormessage displayed, if I click on the save button, the postback goes through. How do I fix this?

<ajaxToolkit:ModalPopupExtender runat="server" ID="mpe_fix"BackgroundCssClass="modalBackground"CancelControlID="btn_Cancel"PopupControlID="pnl_fix"TargetControlID="hdn_dummy" /><asp:Button runat="server" ID="btn_save"Text="Save"ValidationGroup="fix"CausesValidation="true" />

Bump.

Modal Popup: Will not access event handler in code behind prior to showing modal popup.

I have an AJAX modal popup that is tied to a 'Continue' button on a ASP.NET page. The issue is that I have required field validators with messages next to controls that need to be displayed if information is missing. Right now, the AJAX modal shows upon pressing 'Continue' regardless of if infomration is missing on the page. I put a break point in the event handler for the 'Continue' button and it never even gets hit.

How can I intervene and NOT show the modal popup untilall required field validators are satisfied?

if (Page.IsValid)
modalDialogExtender.Show()
else
//do nuthin


Yes and No. When pressing the button that is the TargetControlID of the modal box, the button event handler of that TargetID is is never reached prior to the modal being displayed. That is the No. However, I added a second hidden control as the TargetControlD that can not be accessed from the page to satisfy the modal's proerties. Then when my 'Continue' button is pressed, Yes, the code you provided works and is hit and the modal is shown programatically (assuming PageIsValid = True).

Thank you for the response.