ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

Last post 06-13-2008 5:22 PM by version king. 19 replies.

Sort Posts:

  • ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    05-31-2007, 3:44 PM
    • Member
      428 point Member
    • John.Doe
    • Member since 06-21-2006, 1:54 AM
    • Posts 175

    I have a server side control that embeds text boxes, validation and toolkit extenders. Some of the text boxes are created during postbacks as additional input fields. This works flawlessly if
    a) I do not use the ValidatorCalloutExtender
    b) do always full postbacks
    But as soon as the control is embedded in an UpdatePanel the ValidatorCalloutExtenders break the javascript execution of the page it seems.

    I made a little sample page to demonstrate the behavior:
    TextBox1 is static and always validates correctly: no text -> press OK -> requiredfield error appears and validator callout extender appears
    Now check the CheckBox and press OK again: some javascript error at line 3072

    What Do I do wrong here? I mean creating controls like this is not much different than loading usercontrol dynamically or doesn't that work either with the toolkit?
    (Btw.: I use the validators.dll and the tag mapping in the web.config)

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    
    <script runat="server" type="text/C#">
    
        protected void OnCheckChanged(object sender, EventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;
            this.CreateCheckBox = checkBox.Checked;
            this.RecreateTextBox();
        }
    
        protected bool CreateCheckBox
        {
            get { return this.ViewState["CreateCheckBox"] != null ? (bool)this.ViewState["CreateCheckBox"] : false; }
            set { this.ViewState["CreateCheckBox"] = value; }
        }
    
        protected void RecreateTextBox()
        {
            this.Panel1.Controls.Clear();
            
            if (this.CreateCheckBox)
            {
                TextBox textBox = new TextBox();
                textBox.ID = "TextBox2";
                textBox.Text = "";
                this.Panel1.Controls.Add(textBox);
                RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator();
                requiredFieldValidator.ID = "TextBox2Req";
                requiredFieldValidator.ControlToValidate = "TextBox2";
                requiredFieldValidator.ErrorMessage = "Required";
                this.Panel1.Controls.Add(requiredFieldValidator);
                ValidatorCalloutExtender validatorCalloutExtender = new ValidatorCalloutExtender();
                validatorCalloutExtender.ID = "TextBox2ReqExt";
                validatorCalloutExtender.TargetControlID = "TextBox2Req";
                this.Panel1.Controls.Add(validatorCalloutExtender);
            }
        }
    
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            this.RecreateTextBox();
        }
    
    </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
            <div>            
            
    Works:      <asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
                <asp:RequiredFieldValidator ID="TextBox1Req" runat="server" ControlToValidate="TextBox1" ErrorMessage="Required"></asp:RequiredFieldValidator>
                <ajaxToolkit:ValidatorCalloutExtender ID="TextBox1ReqExt" runat="server" TargetControlID="TextBox1Req"></ajaxToolkit:ValidatorCalloutExtender>            
                
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        Create TextBox: <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckChanged" />
                        <asp:Panel ID="Panel1" runat="server">                
                        </asp:Panel>
                        <br />
                        <br />
                        <br />
                        <asp:Button ID="Button1" runat="server" Text="OK" CausesValidation="true" />
                    </ContentTemplate>
                </asp:UpdatePanel>
                <asp:Button ID="Button2" runat="server" Text="DoPostBack" CausesValidation="false" />
            </div>
        </form>
    </body>
    </html>
    
     
  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-07-2007, 2:20 PM
    • Member
      91 point Member
    • brendalisa
    • Member since 11-29-2006, 4:02 PM
    • Posts 40

    John Doe

     Just wondering if you had ever figured this out ever?  I'm having the same issue with the ValidatorCalloutExtender.

    Thanks!

     Brenda

     

    Brenda
  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-13-2007, 12:31 PM
    • Member
      428 point Member
    • John.Doe
    • Member since 06-21-2006, 1:54 AM
    • Posts 175
    No the problem still exists and is unsolved...
  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-13-2007, 5:18 PM
    • Star
      8,710 point Star
    • David Anson
    • Member since 04-11-2006, 1:39 AM
    • Microsoft
    • Posts 1,842

    http://blogs.msdn.com/delay

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-14-2007, 12:59 PM
    • Member
      428 point Member
    • John.Doe
    • Member since 06-21-2006, 1:54 AM
    • Posts 175

    No, in my case it is an ordinary IE6 ;)

  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-15-2007, 7:40 PM
    • Star
      8,710 point Star
    • David Anson
    • Member since 04-11-2006, 1:39 AM
    • Microsoft
    • Posts 1,842

    Could you please try this with the 10606 release? Your sample works fine for me on the latest code and this sounds vaguely like it might be fixed by one of the changes I made for that release. Thanks!


    http://blogs.msdn.com/delay

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-23-2007, 3:49 PM
    • Member
      428 point Member
    • John.Doe
    • Member since 06-21-2006, 1:54 AM
    • Posts 175

    I did try it today with release 10618 and the error is not the same, but it still does not work:

    Now it gives me directly when the CheckBox is clicked, i.e. the TextBox is created, so the behavior is even worse than before as the error does come up now even before validation of any kind kicks in (example to reproduce as given above):
    Line: 5909
    Character: 12
    Error: Sys.ArgumentUndefinedException: Value cannot be undefined.
        Parameter name: id
    Code: 0

     And there is another bug with the ValidatorCalloutExtender when enabling and disabling Validators.
    I have a TextBox and a DropDownList, depending on the value selected in the DropDownList the TextBox value can either be a string, an int or a floating point number. So I attached three RegularExpressionValidators to that TextBox along with three ValidatorCalloutExtenders, two of the Validators are initially disabled. If I enable/disable validators using 'ValidatorEnable(validatorid, true/false)' the validatorcalloutextender does not notice the change for the following sequence:
    - DropDownList is set to e.g. Int, TextBox value is entered with characters and left, the ValidatorCalloutExtender pops up with the error message of the RegularExpressionValidator - OK
    - change DropDownList value to Float, onchange javascript of the DropDownList disables all validators, enables float RegularExpressionValidator only
    - The ValidatorCalloutExtender still pops up with the old error message on focus of the textbox - not OK

  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-24-2007, 6:18 PM
    • Contributor
      2,610 point Contributor
    • kirtid
    • Member since 11-18-2006, 12:41 AM
    • Redmond
    • Posts 658
    • AspNetTeam

    It may be work item Id=7806.

    Kirti Deshpande
    Program Manager, Silverlight and ASP.NET AJAX
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-25-2007, 11:51 AM
    • Member
      428 point Member
    • John.Doe
    • Member since 06-21-2006, 1:54 AM
    • Posts 175

    I don't think so, I had that bug before, too, and this one is different. If you would just run the little example to reproduce it, you would see that.

    I will try to build a simple example for the validator enable/disable behavior, too, so that hopefully somebody with a clue of how to debug javascript can take a look into that one...

  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-25-2007, 3:14 PM
    • Contributor
      2,610 point Contributor
    • kirtid
    • Member since 11-18-2006, 12:41 AM
    • Redmond
    • Posts 658
    • AspNetTeam

    I tried your code and I am not seeing any javascript errors. But the second callout should be showing and it never does. Also, it attempts to create the behavior twice if you hit postback which actually causes a javascript error. Could you please open a work item on this? We will look into fixing it soon. Thanks.

    Kirti Deshpande
    Program Manager, Silverlight and ASP.NET AJAX
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-26-2007, 2:18 AM
    • Member
      point Member
    • foochuan
    • Member since 06-26-2007, 6:12 AM
    • Posts 2

    I face the same problem and i get my solution from 'csnyder' 

    hope this will help

    csnyder:

    Apparently here's the solution for now......

    http://weblogs.asp.net/scottgu/archive/2007/01/25/links-to-asp-net-ajax-1-0-resources-and-answers-to-some-common-questions.aspx

     The tag is a valid web.config entry but you must first install an updated set of validation control extenders.

    chuck

  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-26-2007, 11:21 AM
    • Member
      428 point Member
    • John.Doe
    • Member since 06-21-2006, 1:54 AM
    • Posts 175

    As said in the first post, I use the validator.dll and the tag mapping of course, otherwise almost nothing would work with validators, that DLL exists almost as of day one of the Atlas Release...

     I could not register to codeplex yesterday because they did some kind of update, I will open a work item for this one today.

  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-26-2007, 2:48 PM
    • Contributor
      2,610 point Contributor
    • kirtid
    • Member since 11-18-2006, 12:41 AM
    • Redmond
    • Posts 658
    • AspNetTeam

    You should use the validators that are part of ASP.NET. If you are any separate validators dll then you may need to switch to using the ASP.NET Validators.

    Kirti Deshpande
    Program Manager, Silverlight and ASP.NET AJAX
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-26-2007, 5:20 PM
    • Member
      428 point Member
    • John.Doe
    • Member since 06-21-2006, 1:54 AM
    • Posts 175

    kirtid:

    You should use the validators that are part of ASP.NET. If you are any separate validators dll then you may need to switch to using the ASP.NET Validators.

    Since when did the set of Atlas compatible validators become absolete? (http://forums.asp.net/t/1066821.aspx)
    If I switch back to the standard validators, then the ValidatorCalloutExtender won't work at all when placed in an UpdatePanel...

  • Re: ValidatorCalloutExtender not working if dynamically created in an UpdatePanel

    06-26-2007, 6:18 PM
    • Contributor
      2,610 point Contributor
    • kirtid
    • Member since 11-18-2006, 12:41 AM
    • Redmond
    • Posts 658
    • AspNetTeam

    You should be using the validators in the System.Web.UI.WebControls namespace which is a part of ASP.NET and *not* the ones in the Compatibility namespace as the forum post suggests.

    There are two posts you should look at:

    http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx - this one talks about the Compatibility namespace going away; It has not been around since the ASP.NET AJAX 1.0 release.

    http://blogs.msdn.com/mattgi/archive/2007/05/12/validators-update-available.aspx - this one suggests that a fix is available and the validators will work inside UpdatePanels.

    Here is what David Anson suggested to me:

    If our users are seeing issues with ValidatorCallout and the UpdatePanel, they should first get the standalone Validator working with the UpdatePanel and then plugin the Callout extender to help us narrow down the problem. If the validator does not work by itself then it is an ASP.NET AJAX issue and should be posted on their forums. If it works fine and the ValidatorCalloutExtender is giving them trouble then we will look into it.

    If there is any confusion caused we apologize.

    Kirti

    Kirti Deshpande
    Program Manager, Silverlight and ASP.NET AJAX
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 2 (20 items) 1 2 Next >