Wednesday, March 28, 2012

Multiple ValidatorCalloutExtender controls

I have a table with multiple fields and validation controls. When I put 2 validatorcalloutextenders on the page only 1 will work on postback. For example, I have a validatorcalloutextender for to requiredfieldvalidators on my page:
1) txtWeight
2) txtProduct

Validation is set to True for my button control on the page. When clicked, only the validatorcalloutextender for txtWeight is displayed. I enter in a weight and tab out of the field and resubmit the page. The 2nd validatorcalloutextender doesn't fire.

I'm guessing that the this has something to do with the updatepanel...

Can you post your code for us?


Hi,

This is very likely be caused by that Validator isn't compatible with UpdatePanel. Please refer to this:

http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx

The following ASP.NET controls are not compatible with partial-page updates, and are therefore not supported inside an UpdatePanel control:

TreeView and Menu controls.

Web Parts controls. For more information, see ASP.NET Web Parts Controls.

FileUpload controls when they are used to upload files as part of an asynchronous postback.

GridView and DetailsView controls when their EnableSortingAndPagingCallbacks property is set to true. The default is false.

Login, PasswordRecovery, ChangePassword, and CreateUserWizard controls whose contents have not been converted to editable templates.

The Substitution control.

Validation controls, which includes the BaseCompareValidator, BaseValidator, CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator, and ValidationSummary control.

And here is a workaround may help: http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx

Hope this helps.


Hello,

I had already implemented the workaround (noted above in Matt's blog) before posting. I don't think the issue is with the original validation controls but rather with the callout extender. The issue is that you have to tab into the 2nd control that is being validated. If you have several controls on your form and the first control and the last control are the controls that need to be validated the last control on your page will not kick off the extender. I've attached a simple example. With this example, when you click the button the 1st extender will kick off. Enter in some text for the first textbox but DO NOT tab to the next textbox. Instead, click on the button. You will see that the extender doesn't execute for he 2nd textbox.

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="testAJAX.aspx.vb"Inherits="testAJAX" %><%@. RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %><!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>  </div> <asp:Button ID="Button1" runat="server" Text="Button" />        <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="t1"></asp:RequiredFieldValidator> <ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" TargetControlID="RequiredFieldValidator1"> </ajaxToolkit:ValidatorCalloutExtender> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="t2"></asp:RequiredFieldValidator> <ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server" TargetControlID="RequiredFieldValidator2"> </ajaxToolkit:ValidatorCalloutExtender> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Only onbe message is shown in specific time.You should focus on other fields to see the errors.

Hmm...that kind of defeats the whole purpose of using the fancy extenders. If I have to write code to send focus to extenders based on what controls have already been validated...well, that's just down right silly!


Well, dotcarlisle's last post is marked as the Answer, but I don't see anything indicating his problem is solved! He just provided an example to reproduce the problem.

I, too am having trouble working with two calloutextenders within an updatepanel. I put dotcarlisle's sample code in a page, ran it, and followed his instructions, and the same exact thing happens in my solution. Why's that post marked as the Answer, though?

That post was done back in July, so I'm wondering if there's been a fix (yes, I have the latest AJAX relase: 10920) or a workaround provided somewhere.

Anyone have any ideas?


Hey capella07. I agree! I'm not sure why that was marked as the answer - if anything it was a mini *** session but a far cry from an answer. I also noticed that the sequence in the messages looks messed up. Why would I reply to someone's reply, or rather advertisement, for Opera?

My guess is that users get deleted and with the user goes that user's posts. In my book that seems to be a bug. THey should keep truncated user's posts around for data consistency...

Anyway, good call, Capella.


Hey, dotcarlisle. Thanks for the nod.

As a quick update, I just tried the "fix" at Matt Gibbs' blog (http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx), and that didn't work.

Frankly I'm very suprised this particular issue with the Toolkit hasn't gotten more attention. Though probably not terribly frequent, seems to me it'd be somewhat common that multiple callout extenders would be needed on a page.

No comments:

Post a Comment