CodeVerge.Net Beta
Login Idy
Register Password
  Forgot?
Explore    Item Entry    Members   
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML





Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 9/1/2005 12:48:36 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 1 Views: 5 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
2 Items, 1 Pages 1 |< << Go >> >|
wirkus
Asp.Net User
Custom Validator not validating9/1/2005 12:48:36 PM

0/0

Hi Everyone,
Im fairly new to asp.net and am trying to create a custom validator. In the code I have posted I have created a custom validator for a DDL which makes a text box enabled if a setup file is selected from the DDL (among other options). The purpose of this text box is to provide a setup file path to include in some release info I am creating for an application. I have then created a custom validator to make sure a path has been included in the text box if it is enabled. The problem I am having is that for some reason my custom validator for my text field where the file path should be entered does not even begin to fire. I would like to do all of this on client side. I would appreciate it if anyone could have a look and give me some suggestions. I have a feeling that it might have something to do with the fact that when I use the custom validator for the DDL to enable or disable the text box, it is doing something to the behaviour of the text box which causes the custom validator for this control (the text box) to NOT fire. I am only a novice so this is really only a stab in the dark. My code is:

<%@ Control Language="vb" AutoEventWireup="false" Codebehind="ActionCreateApplication.ascx.vb" Inherits="ABL.SCM.WEB.UI.ActionCreateApplication" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<div class="ActionContent" id="divContent" runat="server"><asp:panel id="pnlData" runat="server" Height="296px" Width="888px">
  <asp:Label id="lblError" runat="server" Width="848px" ForeColor="Red"></asp:Label>

<asp:DropDownList id="cboInstallType" runat="server" Width="660px"></asp:DropDownList>
  <asp:RequiredFieldValidator id="RequiredFieldValidator7" runat="server" ControlToValidate="cboInstallType" ErrorMessage="RequiredField"
   Display="Dynamic"></asp:RequiredFieldValidator>
  <asp:CustomValidator id="CustomValidator2" runat="server" ControlToValidate="cboInstallType" ErrorMessage="Enter File Path"
   Display="Dynamic" ClientValidationFunction="Custom_ValidateInstallTypeSelected"></asp:CustomValidator>
  <BR>

asp:Label id="lbldataFilepath" runat="server">Enter Install Type file path:</asp:Label>
  <BR>
  <asp:TextBox id="txtSetupFileName" runat="server" Width="660px"></asp:TextBox>
  <asp:CustomValidator id="CustomValidatorSetupFileName" runat="server" ErrorMessage="Setup file path required"
   Display="Dynamic" ClientValidationFunction="Custom_ValidateSetupFileNamePath"></asp:CustomValidator>
  <BR>
</div>

<SCRIPT language="javascript">
var SetUpValue = "<%=InstallTypeListSetUpValue%>";

  function Custom_ValidateInstallTypeSelected (source, args)
  {
  // Default Value
   args.isvalid = true;
   
   var lblDataFilePath = document.all("ucAction_lbldataFilepath");
//ucAction_lbldataFilepath is the name that is automatically generated when the page is run for this code (server side). I got it from viewing the source code when the page was run.

   var txtSetupFileName = document.forms[0].ucAction_txtSetupFileName; 
//ucAction_txtSetupFileName is the name that is automatically generated when the page is run for this code (server side). I got it from viewing the source code when the page was run.

   var cboInstallType = document.forms[0].ucAction_cboInstallType;
//ucAction_cboInstallType is the name that is automatically generated when the page is run for this code (server side). I got it from viewing the source code when the page was run.

  
 if (cboInstallType.options[cboInstallType.selectedIndex].value != SetUpValue)
   {
    lblDataFilePath.disabled = true;
    txtSetupFileName.disabled = true;
    args.isValid = true;
   }
   else
   {
    lblDataFilePath.disabled = false;
    txtSetupFileName.disabled = false;
    args.IsValid = false;
   } 
    
  } 
   
  function Custom_ValidateSetupFileNamePath (source, args)
  {
  // Default Value
   args.isvalid = true;
   var txtSetupFileName = document.forms[0].ucAction_txtSetupFileName;
//ucAction_txtSetupFileName is the name that is automatically generated when the page is run for this code (server side). I got it from viewing the source code when the page was run.

   if (txtSetupFileName.disabled)
   {
       args.isValid = true;
   }
   else
   {
       if (source.text = "")
       {
           args.isValid = false;
       }
       else
       {
           args.isValid = true;
         }
    }
    }
</SCRIPT>

PS I did try a custom Validator with another text box on the same page and that seemed to run alright, it was just with this one particular textbox control.

Thanks for your help
PLBlum
Asp.Net User
Re: Custom Validator not validating9/1/2005 3:06:24 PM

0/0

When you use the CustomValidator, it will NOT fire if the control associated with ControlToValidate is blank. As a rule, when you consider blank text an acceptable value, do not use the ControlToValidate property. See this article for more on this and other knowledge about validators: www.aspalliance.com/699.
--- Peter Blum
Creator of Professional Validation And More Suite, Peter's Date Package, and Peter's Polling Package
www.PeterBlum.com
2 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:

CheckBox Validate is still not supported by Validation Control in ... ... whether or not asp.net 2.0 supports checkbox validator, just like radiobutton. ... how can i create a custom "not authorized" page. extending sitemap. All ...
what happened to onBlur for a textbox... - ng.asp-net-forum ... ... (or that there's a dot-net way -- NOT a validator control, PLEASE -- to do this) ... it with the JavaScript property or weren't using a custom control? ...
ASP.NET QuickStart Tutorials In ASP.NET 1.0 custom validation would not fire if ValidationText was empty. ... custom validation, place your custom validation in the validator's ...
A List Apart: Articles: Validating a Custom DTD The W3C validator won't validate a document with these attributes, as they ... custom DTD isn't one of the publicly registered ones, the DOCTYPE will not use ...
WDG HTML Validator Tips ... is not a technically valid URL, it is accepted by the WDG HTML Validator for convenience. ... By default, the Validator assumes that a custom DTD is HTML or SGML. ...
Walkthrough: Validating User Input in a Web Forms Page You will also create a custom validator with code ... custom validation code is not always practical (for example, if the custom code ...
<VLVALIDATOR> Custom Tag bValid - defines if corresponding custom validator has passed validation. ... If it is not specified, client-side validation for this validator is skipped. ...
Walkthrough: Validating User Input in a Web Forms Page The custom validator allows you to write your own validation code to check for ... custom validation code is not always practical (for example, if the custom code ...


 
All Times Are GMT