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