CustomValidator points to wrong control

Discussion in 'ASP .Net Web Controls' started by David Thielen, Nov 2, 2006.

  1. There is a lot of code below so I will try to explain first. I have a
    Repeater and in the Repeater I have a Panel. In the Panel I have a
    CustomValidator that needs to work with the value of a control that is
    outside the Panel, but inside the Repeater.

    What appears to be happening is that if the Panel is visible, it then calls
    the CustomValidator - but for the CustomValidator in a different row - that
    is hidden.

    Here is my code:
    protected void ValidateMapDatasource(object sender, ServerValidateEventArgs
    args) {
    CustomValidator vldtr = (CustomValidator)sender;
    DropDownList lst = (DropDownList)vldtr.Parent.Parent.FindControl("mapType");
    if (lst.SelectedIndex != 4) {
    args.IsValid = true;
    return;
    }
    // should come to here as SelectedIndex == 4 if the Panel is visible - but
    returns above because it gets the lst for the next row.

    Here is the aspx:
    <asp:Repeater ID="mapRows" runat="server"
    OnItemDataBound="MapDataBind">
    <HeaderTemplate>
    <table width="100%">
    <tr>
    <th>
    <asp:Localize ID="Localize9" runat="server" Text='required'
    /></th>
    <th>
    <asp:Localize ID="Localize10" runat="server" Text='<%$
    Resources:Header, VarName %>' /></th>
    <th>
    <asp:Localize ID="Localize11" runat="server" Text='type' /></th>
    <th>
    <asp:Localize ID="Localize12" runat="server" Text='description'
    /></th>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td>
    <asp:CheckBox ID="mapRequired" runat="server"
    Checked='<%#Eval("Required")%>' /></td>
    <td>
    <asp:Label ID="mapName" runat="server"
    Text='<%#Eval("Name")%>'></asp:Label>
    </td>
    <td>
    <asp:DropDownList ID="mapType" runat="server"
    SelectedIndex='<%#Eval("Type")%>'>
    <asp:ListItem Value="0" Text='<%$ Resources:Value, Currency %>' />
    <asp:ListItem Value="1" Text='<%$ Resources:Value, Date %>' />
    <asp:ListItem Value="2" Text='<%$ Resources:Value, Integer %>' />
    <asp:ListItem Value="3" Text='<%$ Resources:Value, Number %>' />
    <asp:ListItem Value="4" Text='<%$ Resources:Value, Select %>' />
    <asp:ListItem Value="5" Text='<%$ Resources:Value, Text %>' />
    </asp:DropDownList>
    </td>
    <td>
    <asp:TextBox ID="mapDescription" runat="server" Columns="60"
    Rows="4" Height="72px"
    TextMode="MultiLine" />
    <aspWindward:HelpLink ID="HelpLink6" runat="server"
    File="template3" Bookmark="mapvalues" />
    <asp:panel ID="mapSelectPanel" runat="server">
    <br />
    <asp:Localize ID="Localize13" runat="server" Text='<%$
    Resources:prompt, Select %>' />
    <asp:TextBox ID="mapSelect" runat="server" Columns="50"
    Text='<%#Eval("Select")%>'></asp:TextBox>
    <asp:DropDownList ID="mapSelectDatasource" runat="server" />
    <asp:CustomValidator ID="CustomValidator2" runat="server"
    OnServerValidate="ValidateMapDatasource"
    ControlToValidate="mapSelectDatasource" Text="Please select a
    datasource." />
    </asp:panel>
    </td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
    </asp:Repeater>

    Any ideas?

    --
    thanks - dave
    david_at_windward_dot_net
    http://www.windwardreports.com

    Cubicle Wars - http://www.windwardreports.com/film.htm
    David Thielen, Nov 2, 2006
    #1
    1. Advertising

  2. Hi David,

    I have done some test, but wasn't able to reproduce the issue you mentioned.

    First, I don't think the FindControl("mapType") is returning the wrong
    DropDownList, can you verify that, for example: change the found
    DropDownList's SelectedIndex in the validate event.

    During my test, if I bound the repeater in every postback, the state of the
    DropDownList will be lost and the SelectedIndex will always be 0.

    Could you please post the complete webform so that I can test that? Thanks.

    Sincerely,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    promptly.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Nov 3, 2006
    #2
    1. Advertising

  3. I swear this was working wrong yesterday - but it is working fine now. If I
    get the problem again I will get as much info as I can from it.

    --
    thanks - dave
    david_at_windward_dot_net
    http://www.windwardreports.com

    Cubicle Wars - http://www.windwardreports.com/film.htm




    "Walter Wang [MSFT]" wrote:

    > Hi David,
    >
    > I have done some test, but wasn't able to reproduce the issue you mentioned.
    >
    > First, I don't think the FindControl("mapType") is returning the wrong
    > DropDownList, can you verify that, for example: change the found
    > DropDownList's SelectedIndex in the validate event.
    >
    > During my test, if I bound the repeater in every postback, the state of the
    > DropDownList will be lost and the SelectedIndex will always be 0.
    >
    > Could you please post the complete webform so that I can test that? Thanks.
    >
    > Sincerely,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications. If you are using Outlook Express, please make sure you clear the
    > check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    > promptly.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    David Thielen, Nov 3, 2006
    #3
  4. Hi David,

    Please feel free to let me know if the problem occurrs again.

    Have a nice weekend!

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Nov 4, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Heavey

    CustomValidator Control

    Jim Heavey, Dec 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    342
  2. MaxGruven
    Replies:
    7
    Views:
    312
    Steven Cheng [MSFT]
    Jun 9, 2008
  3. Gelonida N
    Replies:
    1
    Views:
    115
    Tim Golden
    Nov 21, 2012
  4. Tim Golden
    Replies:
    0
    Views:
    115
    Tim Golden
    Nov 21, 2012
  5. Gelonida N
    Replies:
    0
    Views:
    177
    Gelonida N
    Nov 21, 2012
Loading...

Share This Page