CustomValidator is hidden

D

David Thielen

Hi;

I have a CustomValidator that is always drawn hidden. I have tried setting
Visible to true in the aspx and aspx.cs files - and it is still hidden. Any
ideas?
 
S

Steven Cheng[MSFT]

Hi Dave,

Thank you for posting.

As for the Custom Validator displaying issue, I think it is mostly a page
specific issue. What's the detailed code/aspx template of that repeater
page? As for custom validator, it will display only when there is
validation error get triggered. Also, are you using client-side validation
or server-side validation?

Regards,

Steven Cheng
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.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

David Thielen

Here you go - all server side:

aspx code:
<asp:Repeater ID="mapRows" runat="server" OnDataBinding="MapBinding"
OnItemDataBound="MapDataBound">
<HeaderTemplate>
<tr>
<th colspan='3'>
Report parameters</th>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="mapName" runat="server"
Text='<%#Eval("Name")%>'></asp:Label>
</td>
<td>
<asp:TextBox ID="mapTextValue" runat="server"
Columns="60"></asp:TextBox>
<asp:CustomValidator ID="mapValidator" runat="server"
ErrorMessage="CustomValidator"
ControlToValidate="mapTextValue">yyy</asp:CustomValidator>
<asp:Calendar ID="mapCalendarValue" runat="server"
Visible="false"></asp:Calendar>
<asp:DropDownList ID="mapListValue" runat="server"
Visible="false"></asp:DropDownList>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>


cs code:
string key = ((Label)ri.FindControl("mapName")).Text;
CustomValidator validator = (CustomValidator)ri.FindControl("mapValidator");
validator.Text = "Please enter a value for the map var " + key;
validator.IsValid = false;

It sets the text but the field is hidden.

Any ideas?

thanks - dave
 
S

Steven Cheng[MSFT]

Hi Dave,

Thanks for your response.

From the code snippet you provided, you define the customvalidator with the
following control template:

=================
<asp:CustomValidator ID="mapValidator" runat="server"
ErrorMessage="CustomValidator"
ControlToValidate="mapTextValue">yyy</asp:CustomValidator>
================

I think the problem here is that you didn't provide a Server-side
validation handler(or client-side validate function) for the custom valiate
control. Also, the error message of Validator control will only display
when the validation occurs(and there is validation error). BTW, custom
validation won't occur when the validating control's Field(such as Text
property is empty).

As for how to write a servervalidation handler, you can reference to the
following msdn document:

#ServerValidateEventHandler Delegate
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontro
lsservervalidateeventhandlerclasstopic.asp?frame=true

Hope this helps.

Regards,

Steven Cheng
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.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

David Thielen

Hi;

Ok, I have it working that way but a couple of things don't make sense.

1) When I click on a button, first it calls the server validation method,
then it calls the button click handler even though the validation method
returned false, then it calls the validation method a second time. So I have
to validate in the button click handler too which makes no sense.

2) I do not have to have an OnServerValidate for any of my other
CustomValidators - just for the one I have inside the Repeater control.

3) It has the validator in the html creates - it's just that it is marked
hidden.
 
S

Steven Cheng[MSFT]

Hi Dave,

Here is my understanding inline:

1) When I click on a button, first it calls the server validation method,
then it calls the button click handler even though the validation method
returned false, then it calls the validation method a second time. So I
have
to validate in the button click handler too which makes no sense.
================================
As for Validation control, when we use server-side validation, the
Validation function of the validators are called after Page Load event, but
before processing postback events. Thus, we can use the Page.IsValid or
ValidatorControl's "IsValid" property determine whether the validation is
passed and our code logic in postback event should also change depend on
this detection.


2) I do not have to have an OnServerValidate for any of my other
CustomValidators - just for the one I have inside the Repeater control.
===============================
Which one(Row) is the one you want to make the validation control enable
validating? I think you can consider using the "ItemCreated" event of
Repeater control to customize certain control in the repeaterItem. Also,
you can consider using DataList control and put your particular validation
control only in the EditTemplate so that only the current Row being edited
will contains the validator control.


3) It has the validator in the html creates - it's just that it is marked
hidden.
=================================
I'm still not quite clear on this. Why would you configure the validator to
be invislbe?

Here are some msdn reference on using validation controls in ASP.NET 2.0:

#Learning More ¡ª Validation Controls
http://msdn2.microsoft.com/en-us/library/ms178317.aspx

Regards,

Steven Cheng
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.



Get Secure! www.microsoft.com/security
(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
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top