B
B. Chernick
I have a customvalidator within an EditItemTemplate, in order to validate a
dropdown list. This is the first time I've tried to implement a cv in
Asp.Net 2.0, let alone a DetailsView. On this page are also several required
field validators for unrelated textboxes. The problem, in summary, is that
when I blank one of those textbox fields and hit Update, the textbox
validator fires as expected but so does the ddl validator for no apparent
reason.
Even more confusing is that that, although I see no other errors, the
windows.alert I put in the javascript funtion is not working. Here is the
html: (The idea is to fire the error if the ddl selected value is -1. Also,
the ddlUnit handle is initialized in VB code during the detailsview DataBound
event.)
<EditItemTemplate>
<aspropDownList ID="ddlUnit" runat="server"
DataSourceID="ObjectDataSourceUnit"
DataTextField="Item" DataValueField="PK">
</aspropDownList>
<asp:CustomValidator ID="cvUnit" runat="server"
ClientValidationFunction="ValidateUnit"
ControlToValidate="ddlUnit" ErrorMessage="Select a
Valid Unit">*</asp:CustomValidator>
<asp:ObjectDataSource ID="ObjectDataSourceUnit"
runat="server"
OldValuesParameterFormatString="{0}"
SelectMethod="GetData"
TypeName="GM_Project_Application_2.GMPATableAdapters.ztblPicklistTableAdapter">
<SelectParameters>
<asparameter DefaultValue="ABACUS"
Name="Group" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<script language="javascript" type="text/javascript">
function ValidateUnit(sender, args)
{
var r = <%= ddlUnit.ClientID %>;
var currentValue = r.GetValue();
window.alert(currentValue);
if (currentValue >= 0)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
</script>
</EditItemTemplate>
dropdown list. This is the first time I've tried to implement a cv in
Asp.Net 2.0, let alone a DetailsView. On this page are also several required
field validators for unrelated textboxes. The problem, in summary, is that
when I blank one of those textbox fields and hit Update, the textbox
validator fires as expected but so does the ddl validator for no apparent
reason.
Even more confusing is that that, although I see no other errors, the
windows.alert I put in the javascript funtion is not working. Here is the
html: (The idea is to fire the error if the ddl selected value is -1. Also,
the ddlUnit handle is initialized in VB code during the detailsview DataBound
event.)
<EditItemTemplate>
<aspropDownList ID="ddlUnit" runat="server"
DataSourceID="ObjectDataSourceUnit"
DataTextField="Item" DataValueField="PK">
</aspropDownList>
<asp:CustomValidator ID="cvUnit" runat="server"
ClientValidationFunction="ValidateUnit"
ControlToValidate="ddlUnit" ErrorMessage="Select a
Valid Unit">*</asp:CustomValidator>
<asp:ObjectDataSource ID="ObjectDataSourceUnit"
runat="server"
OldValuesParameterFormatString="{0}"
SelectMethod="GetData"
TypeName="GM_Project_Application_2.GMPATableAdapters.ztblPicklistTableAdapter">
<SelectParameters>
<asparameter DefaultValue="ABACUS"
Name="Group" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<script language="javascript" type="text/javascript">
function ValidateUnit(sender, args)
{
var r = <%= ddlUnit.ClientID %>;
var currentValue = r.GetValue();
window.alert(currentValue);
if (currentValue >= 0)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
</script>
</EditItemTemplate>