Errors coming from the complex page & and how to disable validators?

Last post 07-24-2008 2:36 PM by Naom. 9 replies.

Sort Posts:

  • Errors coming from the complex page & and how to disable validators?

    07-23-2008, 2:45 PM
    • Loading...
    • Naom
    • Joined on 12-31-2007, 2:08 PM
    • New York
    • Posts 603

    Hi everybody,

    I have a quite complex page with the GridView inside the UpdatePanel. When I select a record in the grid I activate the appropriate FormView (there are several different FormViews and the current FormView depends on Person type). I put all the FormViews into the UpdatePanel as well (otherwise they were not shown) with UpdateMode Conditional and trigger SelectedIndexChanged for the GridView.

    So far so good.

    I tested it at some point and everything worked smoothly. I then worked on other modules in the application and when I'm now trying to test this page I'm getting weird JavaScript errors (in IE) coming from autogenerated code.

    I also have an additional question. I have a static public class with the following code

    /// <summary>

    /// Sets enabled property of the passed controls

    /// </summary>

    /// <param name="cc"></param>

    /// <param name="enabled"></param>

    public static void SetEnabled(ControlCollection cc, bool enabled)

    {

    foreach (Control control in cc)

    {

    if (control is TextBox && control.ID != null)

    ((TextBox)control).ReadOnly = !enabled;

    if (control is DropDownList && control.ID != null)

    ((DropDownList)control).Enabled = enabled;

    if (control is CheckBox && control.ID != null)

    ((CheckBox)control).Enabled = enabled;

    if (control.Controls.Count > 0)

    {

    clseditmode.SetEnabled(control.Controls, enabled);

    }

    }

    }

    This code is called from the UserControls (my forms have UserControls in them) for setting EditMode property. If I set EditMode property to false, I want to somehow remove the validators. Do you have an idea how can I do this?

    Thanks a lot in advance.

  • Re: Errors coming from the complex page & and how to disable validators?

    07-23-2008, 4:05 PM
    • Loading...
    • aadreja
    • Joined on 02-03-2007, 11:36 AM
    • Ahmedabad, India
    • Posts 350
    Same as textbox and dropdown list, set your validators enabled=false or true based on your criteria.

    if (control is RequiredFieldValidator && control.ID != null)

    ((RequiredFieldValidator )control).Enabled = !enabled;

    Apply above for all type of validators you have used.

    Hope it helps, let me know how it goes.

    Thanks,
    Ritesh

    ---------------------------------------------
    Please do not forget to mark as Answer if my reply is helpful.
  • Re: Errors coming from the complex page & and how to disable validators?

    07-23-2008, 4:56 PM
    • Loading...
    • Naom
    • Joined on 12-31-2007, 2:08 PM
    • New York
    • Posts 603
    Yes, I was thinking about something like this as well. Let me try it, but I'm afraid it would not help me to get rid of all these bad weird IE errors.
  • Re: Errors coming from the complex page & and how to disable validators?

    07-23-2008, 5:21 PM
    • Loading...
    • aadreja
    • Joined on 02-03-2007, 11:36 AM
    • Ahmedabad, India
    • Posts 350

    Yes, Please try and let me know if problem exists.

    Thanks,
    Ritesh

    ---------------------------------------------
    Please do not forget to mark as Answer if my reply is helpful.
  • Re: Errors coming from the complex page & and how to disable validators?

    07-23-2008, 5:29 PM
    • Loading...
    • Naom
    • Joined on 12-31-2007, 2:08 PM
    • New York
    • Posts 603
    I tried it and the problem persisted (I mean weird IE7 errors). I commented out all UpdatePanels in that page and I'm re-testing without them. Give me few minutes.
  • Re: Errors coming from the complex page & and how to disable validators?

    07-23-2008, 5:39 PM
    • Loading...
    • Naom
    • Joined on 12-31-2007, 2:08 PM
    • New York
    • Posts 603

    This is really bizarre! I commented out one of the validators with this code

    <!-- Comment out State validator

    <asp:RegularExpressionValidator ID="regexState" runat="server"

    ControlToValidate="txtState" Display="Dynamic" Enabled="false" ErrorMessage="State Requires 2 Capital Letters"

    ValidationExpression="[A-Z]{2}"></asp:RegularExpressionValidator> -->

     

    Why I'm getting errors from the page that tries to access this control? It is commented out! Or may be I can not use <!-- --> comment style like this in a UserControl ?

    Do you see a problem here?

  • Re: Errors coming from the complex page & and how to disable validators?

    07-23-2008, 5:54 PM
    • Loading...
    • Naom
    • Joined on 12-31-2007, 2:08 PM
    • New York
    • Posts 603

    Once I switched to ASP style comments in my UserControls the page started to work (I removed UpdatePanels though).

    I have another weird problem in a different place. I'll update my other thread with more info.

     

     

  • Re: Errors coming from the complex page & and how to disable validators?

    07-24-2008, 1:14 PM
    • Loading...
    • Naom
    • Joined on 12-31-2007, 2:08 PM
    • New York
    • Posts 603

    Here is the weird part. When I try to open my form (when I'm using UpdatePanels), I'm getting an error here:

    function ValidatorOnLoad() {

    if (typeof(Page_Validators) == "undefined")

    return;

    var i, val;

    for (i = 0; i < Page_Validators.length; i++) {

    val = Page_Validators[i];

    if (typeof(val.evaluationfunction) == "string") {  // The error is on this line

    eval("val.evaluationfunction = " + val.evaluationfunction + ";");

    }

    In the debugger I see that I have 16 validators, but for some reason the 3rd [2] validator is null. I could not figure out what could be the problem.

    The null validator is between FirstName, LastName validators and DOB validator.

    Here is the UserControl ASPX definition:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="GeneralInfo.ascx.cs" Inherits="Coordinator_UCD_GeneralInfo" Description = "General Information Tab" %>

    <%--<%@ Register src="DateCombo.ascx" tagname="DateCombo" tagprefix="uc1" %>

    --%>

    <%@ Register Assembly="RJS.Web.WebControl.PopCalendar" Namespace="RJS.Web.WebControl" TagPrefix="rjs" %>

    <asp:Panel ID="pnlIsActive" runat="server" BorderStyle="None" Visible="False"

    CssClass ="cl" Width = "100%">

    <label class="bx">Active</label>

    <span class="bx" style="width: 20px"><asp:CheckBox ID="chkActive"

    runat="server" />

    </span></asp:Panel>

    <div class="cl">

    <label class="bx">First Name </label><span class="bx"><asp:TextBox ID="txtFirstName" Text='' MaxLength="25" runat="server"/>

    <asp:RequiredFieldValidator ID="rqfvFirstName" runat="server" ControlToValidate="txtFirstName" ErrorMessage="First Name is Required" Display="Dynamic"></asp:RequiredFieldValidator></span>

    <label class="bx">Middle Name </label><span class="bx"><asp:TextBox ID="txtMiddleName" Text='' MaxLength="25" runat="server"/></span>

    <label class="bx">Last Name </label><span class="bx"><asp:TextBox ID="txtLastName" Text='' MaxLength="30" runat="server"/>

    <asp:RequiredFieldValidator ID="rqfvLastName" runat="server"

    ControlToValidate="txtLastName"

    ErrorMessage="Last Name is Required" Display="Dynamic"></asp:RequiredFieldValidator></span></div>

    <asp:Panel ID="pnlTitle" runat="server" BorderStyle="None" Visible="False"

    CssClass ="cl" Width = "100%">

    <label class="bx">Title </label>

    <span class="bx">

    <asp:TextBox ID="txtTitle" runat="server" AutoCompleteType="Disabled"

    MaxLength="50" Text=''></asp:TextBox>

    <asp:RequiredFieldValidator ID="rqfvTitle" runat="server"

    ControlToValidate="txtTitle" Display="Dynamic" Visible = "false"

    ErrorMessage="Title is Required"></asp:RequiredFieldValidator></span>

    </asp:Panel>

    <div class="cl"><label class="bx">Gender</label><span class="bx"><asp:DropDownList ID="ddlGender"

    runat="server" CssClass="gndr" ToolTip="Select Gender"

    onSelectedIndexChanged="OnGenderChanged">

    <asp:ListItem Value="M">Male</asp:ListItem>

    <asp:ListItem Value="F">Female</asp:ListItem>

    </asp:DropDownList></span>

    </div>

    <%--<div class="cl">

    <asp:Panel ID="pnlDOB" runat="server" BorderStyle="None"

    CssClass ="cl" Width = "100%">

    <label class="bx">Date of Birth</label>

    <span class="bx dob"><uc1:DateCombo ID="dcDOB" PopulateOnPostBack="true" runat="server" /></span></asp:Panel>

    </div>--%>

    <div class="cl">

    <label class="bx">Date of Birth</label>

    <span class="bx dob">

    <asp:TextBox ID="txtDOB" AutoCompleteType="disabled" TextMode="SingleLine" runat="server" />

    <rjs:PopCalendar ID="popcalDOB" runat="server" BorderWidth="" Language="" SelectedDate=""

    control="txtDOB" Fade="1" Format="m d yyyy" Separator="/" />

    <asp:RequiredFieldValidator ID="rqfvDOB" runat="server" ControlToValidate="txtDOB"

    ErrorMessage="Date of Birth is Required" Display="Dynamic"></asp:RequiredFieldValidator>

    <asp:RegularExpressionValidator ID="regexDoB" runat="server" ControlToValidate="txtDOB"

    Display="Dynamic" ErrorMessage="Incorrect Date of Birth (m/d/yyyy)"

    ValidationExpression="(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[13-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})"></asp:RegularExpressionValidator>

     </span>

    </div>

    <div class="cl">

    <asp:Panel ID="pnlParents" runat="server" BorderStyle="None"

    Width="100%" Height="65px" HorizontalAlign ="Left" >

    <label class="bx">

    Father

    </label>

    <span class="bx">

    <asp:TextBox ID="txtFather" runat="server" AutoCompleteType="Disabled"

    MaxLength="100" Text=''></asp:TextBox>

    </span>

    <label class="bx">

    Father Cell

    </label>

    <span class="bx">

    <asp:TextBox ID="txtFatherCell" runat="server" AutoCompleteType="Disabled"

    MaxLength="25" Text=''></asp:TextBox>

     

    <%
    --<asp:RegularExpressionValidator ID="regexvlFatherCell" runat="server"

    ControlToValidate="txtFatherCell" Display="Dynamic" Enabled ="false"

    ErrorMessage="Incorrect Cell Phone"

    ValidationExpression="(\([2-9]\d{2}\)\s?|[2-9]\d{2}-|[2-9]\d{2}\s?)[1-9]\d{2}(-|\s)?\d{4}\s?(([xX]|[eE][xX][tT])(#|:)?\s?\d+)?"></asp:RegularExpressionValidator>--
    %>

    </span>

    <br /><br />

    <label class="bx">

    Mother

    </label>

    <span class="bx">

    <asp:TextBox ID="txtMother" runat="server" AutoCompleteType="Disabled"

    MaxLength="100" Text=''></asp:TextBox>

    </span>

    <label class="bx">

    Mother Cell

    </label>

    <span class="bx">

    <asp:TextBox ID="txtMotherCell" runat="server" AutoCompleteType="Disabled"

    MaxLength="25" Text=''></asp:TextBox>

     

    <%
    --<asp:RegularExpressionValidator ID="regexvlMotherCell" runat="server"

    ControlToValidate="txtMotherCell" Display="Dynamic" enabled ="false"

    ErrorMessage="Incorrect Cell Phone"

    ValidationExpression="(\([2-9]\d{2}\)\s?|[2-9]\d{2}-|[2-9]\d{2}\s?)[1-9]\d{2}(-|\s)?\d{4}\s?(([xX]|[eE][xX][tT])(#|:)?\s?\d+)?"></asp:RegularExpressionValidator>--
    %>

    </span>

    </asp:Panel></div>  

    I see nothing's wrong here, so I don't understand where this null validator is coming from... And since this is auto-generated code I have no control over it.

    The only solution is to comment out all update panels. Then the page works correctly, but I get the whole page refresh - that's the downside.

    I don't have the same problem in FireFox. I think in FireFox this error is just silently ignored.

  • Re: Errors coming from the complex page & and how to disable validators?

    07-24-2008, 1:48 PM
    • Loading...
    • aadreja
    • Joined on 02-03-2007, 11:36 AM
    • Ahmedabad, India
    • Posts 350

    this error is due to missing brackets '}' in your javascript.

    try this

    function ValidatorOnLoad()
            {
                if (typeof(Page_Validators) == "undefined")
                    return;

                var i, val;
                for (i = 0; i < Page_Validators.length; i++)
                {

                    val = Page_Validators[i];
                    if (typeof(val.evaluationfunction) == "string")
                    { 
                        // The error is on this line
                        eval("val.evaluationfunction = " + val.evaluationfunction + ";");
                    }
                }
            }

    Thanks,
    Ritesh

    ---------------------------------------------
    Please do not forget to mark as Answer if my reply is helpful.
  • Re: Errors coming from the complex page & and how to disable validators?

    07-24-2008, 2:36 PM
    • Loading...
    • Naom
    • Joined on 12-31-2007, 2:08 PM
    • New York
    • Posts 603

    The JavaScript code is correct and this is not my code, otherwise I would just add an extra check

    if (val)

    ..

    The code is autogenerated by MS AJAX. But in my case for unknown reason I have an array of Page_Validators but some of them are null. I don't understand how did it happen and that's why I posted one of my UserControls, since I think the error is coming from it. At least 2 normal validators are from it, then one null, then again one from it. 

     

Page 1 of 1 (10 items)