CustomValidator points to wrong control

D

David Thielen

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
W

Walter Wang [MSFT]

Hi David,

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

Have a nice weekend!

Regards,
Walter Wang ([email protected], 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top