Showing posts with label field. Show all posts
Showing posts with label field. 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(); }

Modal Popup Problem Inside Multiview

I have a multiview with six views. Each view has a date field with a imagebutton beside it. When you click the imagebutton is should open a modal popup. The modal popup holds a canledar control. When I bring up this page with the multiview I get the following error: "Assertion Failed: Could not find an HTML element with ID "ImageButton ....." for control of type "sys.UI.Image".

I understand why I get this error, and that's because the imagebutton control exists on the second view that is hidden (because it works on the first view if it's the only one defined to use modal popup) . So then I tried to move the ModalPopupExtender to be within the views. Then when I move to the second view I get "null or not null object" error in the WebResource.axd line 110. The actual statement is "$(_CancelControlID).detachEvent('onclick', _cancelHandler);". I really need to get this working ASAP. If I can make this work with just the Popup (not Modal Popup) that would also be OK, but I have to call the popup from the ImageButton....

As you note, different panels of a MultiView are in many ways like completely separate pages. I like your idea of moving the MPE into the same view as the target control. Does that layout work if you remove the MultiView entirely? If not, then maybe it's something else getting in the way.

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.