Re: CustomValidator problems
- From: v-alchen@xxxxxxxxxxxxxxxxxxxx (Allen Chen [MSFT])
- Date: Fri, 26 Sep 2008 10:07:59 GMT
Hi Epetruk,
Have you solved this issue?
Regards,
Allen Chen
Microsoft Online Community Support
--------------------
| From: "Epetruk" <nobody@xxxxxxxxxxxxx>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet,microsoft.public.dotnet.framework.a
spnet.webcontrols
| References: <O80zk.55831$T82.48356@xxxxxxxxxxxxx>
<KHjzk.28472$Fa6.25168@xxxxxxxxxxxxx>
| Subject: Re: CustomValidator problems
| Lines: 119
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
| Message-ID: <kJDBk.89173$Qu7.87022@xxxxxxxxxxxxx>
| X-Complaints-To: abuse@xxxxxxxxxxxx
| NNTP-Posting-Date: Mon, 22 Sep 2008 02:49:52 UTC
| Date: Sun, 21 Sep 2008 19:49:50 -0700
| Path:
TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTFEEDS01.phx.gbl!tornado.f
astwebnet.it!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!t-o
nline.de!newsfeed.freenet.de!feeder.news-service.com!feed.xsnews.nl!border-3
ams.xsnews.nl!eweka.nl!hq-usenetpeers.eweka.nl!69.16.177.246.MISMATCH!cyclo
ne03.ams.highwinds-media.com!news.highwinds-media.com!npeersf01.ams.highwind
s-media.com!newsfe25.ams2.POSTED!99621442!not-for-mail
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:4004
microsoft.public.dotnet.framework.aspnet:76495
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
|
| "Epetruk" <nobody@xxxxxxxxxxxxx> wrote in message
| news:KHjzk.28472$Fa6.25168@xxxxxxxxxxxxxxxx
| > Any one have any ideas about this issue?
| >
| > Epetruk
| >
| > "Epetruk" <nobody@xxxxxxxxxxxxx> wrote in message
| > news:O80zk.55831$T82.48356@xxxxxxxxxxxxxxxx
| >> Hello,
| >>
| >> I have an ASP.NET page which consists of a button (cmdSave), a label
| >> (lblMessage), a text field (txtName) and a custom validator (vldName).
| >>
| >> vldName is supposed to do both client *and* server validation of
txtName;
| >> the custom validation function is ValidateName, and the server
validation
| >> function is ValidateNameOnServer.
| >>
| >> This validation should occur when cmdSave is clicked. If no text has
been
| >> entered, the validation should fail and an error message should be
| >> printed on lblMessage; else the validation should succeed, and
lblMessage
| >> should be blank.
| >>
| >> Unfortunately, I am having problems triggering both ValidateName or
| >> ValidateNameOnServer. The alert won't go off in ValidateName, and when
I
| >> put a breakpoint in ValidateNameOnServer, it isn't hit.
| >>
| >>
| >>
| >> Heres the code for the page:
| >>
| >> <HTML>
| >> <HEAD>
| >>
| >> ...
| >>
| >> <script type="text/javascript">
| >> function ValidateName(sender, args)
| >> {
| >> alert("In ValidateName.");
| >> //var elem = getElementById("<% =lblMessage.ClientID %>");
| >> if (args.Value.length != 0)
| >> {
| >> //elem.Value = "";
| >> args.IsValid = true;
| >> return true;
| >> }
| >> else
| >> {
| >> //elem.Value = "Name is required.";
| >> args.IsValid = false;
| >> return false;
| >> }
| >> }
| >> </script>
| >> </HEAD>
| >>
| >> <body>
| >> <form id="Form1" method="post" runat="server">
| >> <asp:TextBox id="txtName" style="Z-INDEX: 105; LEFT: 107px;
POSITION:
| >> absolute; TOP: 38px" runat="server"></asp:TextBox>
| >> <asp:Button id="cmdSave" style="Z-INDEX: 113; LEFT: 218px; POSITION:
| >> absolute; TOP: 74px" runat="server" Text="Save"
| >> OnClick="cmdSave_Click"></asp:Button>
| >> <asp:CustomValidator ID="vldName" runat="server"
| >> style="position:absolute; left: 268px; top: 39px;"
| >> ErrorMessage="Name cannot be blank;"
| >> ClientValidationFunction="ValidateName"
| >> OnServerValidate="ValidateNameOnServer"
| >> ControlToValidate="txtName">*</asp:CustomValidator>
| >> <asp:Label ID="lblMessage" runat="server"
style="position:absolute;
| >> left: 104px; top: 122px;" Width="253px"></asp:Label>
| >> </form>
| >> </body>
| >> </HTML>
| >>
| >>
| >>
| >> Here's the code for ValidateNameOnServer in the codebehind:
| >>
| >> protected void ValidateNameOnServer(object source,
| >> ServerValidateEventArgs args)
| >> {
| >> if (args.Value.Length == 0)
| >> {
| >> args.IsValid = false;
| >> }
| >> else
| >> {
| >> args.IsValid = true;
| >> }
| >> }
| >>
| >>
| >> I'd appreciate it if anyone could shed any light on what I am doing
| >> wrong, or what I am missing out.
| >>
| >> Epetruk
| >>
| >
| >
|
| Still no answer...
|
| Anyway, I found out some more - I notice that the client validation
function
| (ValidateName) *is* triggered when I enter a value in the text box (that
is
| supposed to be validated), but it is *not* triggered when the text box is
| empty. (I found out by putting alerts.)
|
| I also found that no matter what I do, the server validation function
| (ValidateNameOnServer) is not being fired. I removed all the client
| validation, but it made no difference - it still didnt fire.
|
| I'd really, really appreciate it if someone could help. I'm sure it's
| something fairly straightforward.
|
| E.
|
|
|
.
- Prev by Date: Re: populate control in ascx
- Next by Date: Re: Validating user controls
- Previous by thread: Re: CustomValidator problems
- Next by thread: Difference between Button click and IPostBackEventHandler
- Index(es):