Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Customvalidator problem within Detailsview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
B. Chernick - 04 Dec 2007 14:15 GMT
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>
                 
                   <asp:DropDownList ID="ddlUnit" runat="server"
DataSourceID="ObjectDataSourceUnit"
                       DataTextField="Item" DataValueField="PK">
                   </asp:DropDownList>
                   <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>
                           <asp:Parameter 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>
bruce barker (sqlwork.com) - 04 Dec 2007 16:36 GMT
Unless you've added the code, a ddl does not have a GetValue() method, nor do
you need one, as the value is passed.  also to do a numeric compare, you need
a cast

try:

  function ValidateUnit(sender, args)
  {
      args.IsValid =  (new Number(args.Value)) >=  0;
      return args.IsValid;
  }


-- bruce (sqlwork.com)

> 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
[quoted text clipped - 49 lines]
>     </script>
>                 </EditItemTemplate>
B. Chernick - 05 Dec 2007 20:51 GMT
Thanks!  Worked perfectly.  

(Even better, I can use one function to validate all my dropdowns. That
excessively complex javascript function was modeled after ones in my previous
job where we were using nothing but guid values and 3rd party dropdowns.)

> Unless you've added the code, a ddl does not have a GetValue() method, nor do
> you need one, as the value is passed.  also to do a numeric compare, you need
[quoted text clipped - 64 lines]
> >     </script>
> >                 </EditItemTemplate>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.