I have a Modal popup with some textboxes and a OK button, i have placed required field validators to
respective textboxes with "DiscountValidate" as ValidationGroup. The Ok button has the
same ValidationGroup.
But when the Modal popup opens, the required field validator is not working when clicking on
OK button. I need to implement validation in Modal -popup.
And how do u apply the same for a grid inside Modal popup
ModalPopup's OK button is a special case for client side validation. If you want to enable validation easily, I'd recommend you leave the popup's OkControlID empty, let the Button cause a postback so it will trigger clientside validation, and then wrap the
whole thing in an UpdatePanel so you don't see the postback. You can do this a couple different ways, but that's probably the easiest.
Thanks,
Ted
This posting is provided "AS IS" with no warranties, and confers no rights.
You can manually execute the validators and close the ModalPopupExtender once validation is successful.
You have to do the following:
Don't set a OkControlID or an OnOkScript on the ModalPopupExtender. This will ensure that the ModalPopupExtender doesn't close automatically when the "OK" button is clicked.
Call a javascript funtion in the "click" event of the OK button. After the function call, return false so that the form doesn't post back (i.e. onclick="ValidateData(); return false;"). Inside this function you can do something like
var popup = $find(
"<%= this.YourModalPopupExtenderId.BehaviorID %>" );
if (popup) {
if ( Page_ClientValidate(
"<%= this.YourOKButtonID.ValidationGroup %>" ) ) {
// Data is valid, you can close the popup.
popup.hide();
}
}
The Page_ClientValidate is a javascript funtion that is render with the page (Microsoft ASP.NET javascript code).
Can you please give some more information about what "isn't working"?
Are you getting a javascript error message?
The validators are validating?
The popup isn't closing?
Try debugging the javascript code. You can get add-ons for FireFox or Visual Studio 2008 supports better javascript debugging.
Also, you can view the source of the page to ensure that the webresource.asx script tags are rendering and attempt to download the file yourself.
For example, you might see something like this in the page source:
<script src="/WebResource.axd?d=xMYMDZvs-JAyX1EElVSbsg2&t=633223171829708750" type="text/javascript">
i already add the add-on in firefox.I m not getting the javascript error.
But error is that i set the require field validation on the control Validation is fire but the Message not display to user like i put * corresponding to the control.which is blank that * is not visible to the user.
Try removing the "InitialValue" property of the RequiredFieldValidator control.
You have it set to -1, which I am assuming that is suppose to be a non-existence item index.
The RequiredFieldValidator looks at the DropDownList's SelectedValue, therefore, you would have to have a DropDownList Item with a value of "-1" for this to work.
Thanks a ton @Garry. Your post turned my research into the right direction. I finally have working ModalPopExtender implemented in my app by referring the following links:
1. http://mattberseth.com/blog/2007/07/confirm_gridview_deletes_with.html : Excellent post by Matt. Enough detail to both understand and implement a ModalPopupExtender
2. MSDN Links to read about client validation sequence/validation sequence in ASP.NET:
Adding the information for the benefit of newbees like me.
I still have one issue (workaround for now). After calling Page_ClientValidate with my validation group name, the client side event handlers get disabled. For e.g., if I click on a button, the first time nothing happens. On second click only the event handler
fires. Ditto for a drop down list that has an onselctionchange handler. If someone has a clue, please post back.
vishaal
Member
1 Points
5 Posts
Problem with AJAX Modal Popup + Validation Summary
Mar 05, 2007 10:39 AM|LINK
I have a Modal popup with some textboxes and a OK button, i have placed required field validators to
respective textboxes with "DiscountValidate" as ValidationGroup. The Ok button has the
same ValidationGroup.
But when the Modal popup opens, the required field validator is not working when clicking on
OK button. I need to implement validation in Modal -popup.
And how do u apply the same for a grid inside Modal popup
thanks
Vishaal
Ted Glaza [M...
Contributor
4198 Points
847 Posts
AspNetTeam
Re: Problem with AJAX Modal Popup + Validation Summary
Mar 08, 2007 07:18 PM|LINK
ModalPopup's OK button is a special case for client side validation. If you want to enable validation easily, I'd recommend you leave the popup's OkControlID empty, let the Button cause a postback so it will trigger clientside validation, and then wrap the whole thing in an UpdatePanel so you don't see the postback. You can do this a couple different ways, but that's probably the easiest.
Thanks,
Ted
Garry English
Member
87 Points
20 Posts
Re: Problem with AJAX Modal Popup + Validation Summary
Jan 11, 2008 08:32 AM|LINK
You can manually execute the validators and close the ModalPopupExtender once validation is successful.
You have to do the following:
- Don't set a OkControlID or an OnOkScript on the ModalPopupExtender. This will ensure that the ModalPopupExtender doesn't close automatically when the "OK" button is clicked.
- Call a javascript funtion in the "click" event of the OK button. After the function call, return false so that the form doesn't post back (i.e. onclick="ValidateData(); return false;"). Inside this function you can do something like
var popup = $find( "<%= this.YourModalPopupExtenderId.BehaviorID %>" ); if (popup) { if ( Page_ClientValidate( "<%= this.YourOKButtonID.ValidationGroup %>" ) ) { // Data is valid, you can close the popup.popup.hide();
}
} The Page_ClientValidate is a javascript funtion that is render with the page (Microsoft ASP.NET javascript code).
Thanks
chauhanvivek27
Member
20 Points
18 Posts
Re: Problem with AJAX Modal Popup + Validation Summary
Jan 16, 2008 06:38 AM|LINK
Great Man it fine
it work good thanks
Dear
chauhanvivek27
Member
20 Points
18 Posts
Re: Problem with AJAX Modal Popup + Validation Summary
Jan 16, 2008 06:41 AM|LINK
But this not work When i upload it on the hosting server...............
Please help me..
Thanks..............
Garry English
Member
87 Points
20 Posts
Re: Problem with AJAX Modal Popup + Validation Summary
Jan 16, 2008 06:59 AM|LINK
Can you please give some more information about what "isn't working"?
Are you getting a javascript error message?
The validators are validating?
The popup isn't closing?
Try debugging the javascript code. You can get add-ons for FireFox or Visual Studio 2008 supports better javascript debugging.
Also, you can view the source of the page to ensure that the webresource.asx script tags are rendering and attempt to download the file yourself.
For example, you might see something like this in the page source:
<script src="/WebResource.axd?d=xMYMDZvs-JAyX1EElVSbsg2&t=633223171829708750" type="text/javascript">
Then in your browser, type the following to download the file:
http://yourUrlHere.com/WebResource.axd?d=xMYMDZvs-JAyX1EElVSbsg2&t=633223171829708750
Thanks
chauhanvivek27
Member
20 Points
18 Posts
Re: Problem with AJAX Modal Popup + Validation Summary
Jan 16, 2008 10:38 AM|LINK
Hi Garry
i already add the add-on in firefox.I m not getting the javascript error.
But error is that i set the require field validation on the control Validation is fire but the Message not display to user like i put * corresponding to the control.which is blank that * is not visible to the user.
Code is below.
<td class="lalign">
Asset:</td>
<td class="lalign">
<asp:DropDownList ID="ddlasset1" runat="server" AppendDataBoundItems="true">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator20" runat="server" ControlToValidate="ddlasset1"
ValidationGroup="Add" InitialValue="-1" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
Garry English
Member
87 Points
20 Posts
Re: Problem with AJAX Modal Popup + Validation Summary
Jan 16, 2008 10:57 AM|LINK
Hello,
Try removing the "InitialValue" property of the RequiredFieldValidator control.
You have it set to -1, which I am assuming that is suppose to be a non-existence item index.
The RequiredFieldValidator looks at the DropDownList's SelectedValue, therefore, you would have to have a DropDownList Item with a value of "-1" for this to work.
Thanks
chauhanvivek27
Member
20 Points
18 Posts
Re: Problem with AJAX Modal Popup + Validation Summary
Jan 16, 2008 12:49 PM|LINK
Hi
I add the --Select-- on the -1 index in drop down .
So at -1 there is item in the Dropdown.Problem is that * is not visible when Validation fire.
sudhanshu.mi...
Member
8 Points
7 Posts
Re: Problem with AJAX Modal Popup + Validation Summary
Mar 09, 2010 10:10 AM|LINK
Thanks a ton @Garry. Your post turned my research into the right direction. I finally have working ModalPopExtender implemented in my app by referring the following links:
1. http://mattberseth.com/blog/2007/07/confirm_gridview_deletes_with.html : Excellent post by Matt. Enough detail to both understand and implement a ModalPopupExtender
2. MSDN Links to read about client validation sequence/validation sequence in ASP.NET:
http://msdn.microsoft.com/en-us/library/aa479302.aspx
http://msdn.microsoft.com/en-us/library/aa479045.aspx
Adding the information for the benefit of newbees like me.
I still have one issue (workaround for now). After calling Page_ClientValidate with my validation group name, the client side event handlers get disabled. For e.g., if I click on a button, the first time nothing happens. On second click only the event handler fires. Ditto for a drop down list that has an onselctionchange handler. If someone has a clue, please post back.