<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Dave Kehring - ASP.NET</title>
    <link>http://blog.whconsult.com/</link>
    <description>partial class DaveKehring : IProgrammer { } </description>
    <language>en-us</language>
    <copyright>Dave Kehring</copyright>
    <lastBuildDate>Tue, 23 Oct 2007 12:34:45 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>dave.kehring@whconsult.com</managingEditor>
    <webMaster>dave.kehring@whconsult.com</webMaster>
    <item>
      <trackback:ping>http://blog.whconsult.com/Trackback.aspx?guid=3eb096ba-079a-451a-9fad-0ae4a2a2587e</trackback:ping>
      <pingback:server>http://blog.whconsult.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.whconsult.com/PermaLink,guid,3eb096ba-079a-451a-9fad-0ae4a2a2587e.aspx</pingback:target>
      <dc:creator>Dave Kehring</dc:creator>
      <wfw:comment>http://blog.whconsult.com/CommentView,guid,3eb096ba-079a-451a-9fad-0ae4a2a2587e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.whconsult.com/SyndicationService.asmx/GetEntryCommentsRss?guid=3eb096ba-079a-451a-9fad-0ae4a2a2587e</wfw:commentRss>
      <title>Creating a Client-side Validator for the DropDownList</title>
      <guid isPermaLink="false">http://blog.whconsult.com/PermaLink,guid,3eb096ba-079a-451a-9fad-0ae4a2a2587e.aspx</guid>
      <link>http://blog.whconsult.com/2007/10/23/CreatingAClientsideValidatorForTheDropDownList.aspx</link>
      <pubDate>Tue, 23 Oct 2007 12:34:45 GMT</pubDate>
      <description>&lt;div&gt;I like using Guids. Sure, they're a bit long and difficult to decipher in a database
but they have their uses. I typically use them as the primary key for database tables.
I often have the need to display a list of values from a database table in a DropDownList
control on a WebForm. The value of each entry is the Guid while the text value comes
from a description field in each record. When the user selects an item from the DropDownList,
I retreive the Guid from the SelectedValue property which is typically used to set
a field on a business object, thus creating a reference. Typically the first item
in the DropDownList reads "--Select One--" or "-- None --", indicating the the user
must select a value (this is represented by the value for Guid.Empty). Consequently
the field is "required" - a user must select a value from the list. I do this because
I don't want to presume a default value (such as the first item). 
&lt;br&gt;
&lt;br&gt;
The problem them becomes how to validate the DropDownList on the client side such
that if the user does not select an item other than the default "--Select One--" item
a message is display. 
&lt;br&gt;
&lt;br&gt;
I found a &lt;a href="http://www.netomatix.com/development/DropDownCustomValidator.aspx"&gt;post &lt;/a&gt;that
shows how to use the CustomValidator control to validate a DropDownList. The problem
with this solution is that it does not take into account when a control is embedded
within other controls that are tagged with the INamingContainer interface. This interface
tells ASP.NET to automatically generate unique "id" attribute values on the ensuing
HTML tags generated for a control. This unique id is prepended with the id of each
parent control up to the root control. For example, a DropDownList embedded in a Panel
control might have the id "ctl00$ddlMyDropDown". Therefore, in the solution mentioned
above, we can't simply us "document.getElementById" Javascript function to locate
the DropDownList control. 
&lt;br&gt;
&lt;br&gt;
A better solution is to utilize the ControlToValidate property of the CustomValidator
control. When this is set at design-time ASP.NET will generate Javascript code to
add this value as an attribute of the validator control in the HTML DOM. For instance,
looking at the source of the page I'm working on the following code is generated: 
&lt;br&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;var ctl00_MainContent_CustomValidator1 = document.all
? document.all["ctl00_MainContent_CustomValidator1"] : document.getElementById("ctl00_MainContent_CustomValidator1");&lt;/font&gt; 
&lt;br&gt;
&lt;font face="courier new" size=2&gt;&lt;strong&gt;ctl00_MainContent_CustomValidator1.controltovalidate
= "ctl00_MainContent_ddlFeedbackType";&lt;/strong&gt;&lt;/font&gt; 
&lt;br&gt;
&lt;font face="Courier New" size=2&gt;&lt;/font&gt;
&lt;br&gt;
&lt;font size=2&gt;The property "controltovalidate" contains the fully-qualified unique
id of the target control we're validating. We can use the "controltovalidate" property
in our Javascript function that is used to validate the DropDownList:&lt;/font&gt; 
&lt;br&gt;
&lt;font size=2&gt;&lt;/font&gt;
&lt;br&gt;
&lt;script type=text/javascript&gt;    &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;function ValidateFeedbackType(source, arguments)    &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;{&lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;    var ddl = document.getElementById(source.controltovalidate);&lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;    if (null != ddl)        &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;    {            &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;        var value = ddl[ddl.selectedIndex].value;            &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;        arguments.IsValid = (value != "00000000-0000-0000-0000-000000000000");&lt;/font&gt;
&lt;br /&gt;&lt;font face="Courier New"&gt;&lt;font size="2"&gt;    &lt;font size="+0"&gt;}        &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;    else        &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;    {            &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;        arguments.IsValid = false;        &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;    }    &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;}    &lt;/font&gt;
&lt;br /&gt;&lt;font face="courier new" size="2"&gt;&lt;/script&gt;
&lt;font face="courier new" size=2&gt;function ValidateFeedbackType(source, arguments) &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;{ &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;var ddl = document.getElementById(source.controltovalidate); &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;if (null != ddl) &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;{ &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;var value = ddl[ddl.selectedIndex].value; &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;arguments.IsValid = (value != "00000000-0000-0000-0000-00000000000"); &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;} &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;else &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;{ &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;arguments.IsValid = false; &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;} &lt;/font&gt;
&lt;br&gt;
&lt;font face="courier new" size=2&gt;}&lt;/font&gt; 
&lt;br&gt;
&lt;p&gt;
&lt;font face="courier new" size=2&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="courier new" size=2&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;
&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://blog.whconsult.com/aggbug.ashx?id=3eb096ba-079a-451a-9fad-0ae4a2a2587e" /&gt;</description>
      <comments>http://blog.whconsult.com/CommentView,guid,3eb096ba-079a-451a-9fad-0ae4a2a2587e.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://blog.whconsult.com/Trackback.aspx?guid=220306df-6140-4f05-ba3b-8b843c062cee</trackback:ping>
      <pingback:server>http://blog.whconsult.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.whconsult.com/PermaLink,guid,220306df-6140-4f05-ba3b-8b843c062cee.aspx</pingback:target>
      <dc:creator>Dave Kehring</dc:creator>
      <wfw:comment>http://blog.whconsult.com/CommentView,guid,220306df-6140-4f05-ba3b-8b843c062cee.aspx</wfw:comment>
      <wfw:commentRss>http://blog.whconsult.com/SyndicationService.asmx/GetEntryCommentsRss?guid=220306df-6140-4f05-ba3b-8b843c062cee</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm using VS.NET 2003, SQL Server 2000.
</p>
        <p>
In my case, the error "internal connection fatal error" was being generated when using
a DataReader to read the field values of a record. As I stepped through the code in
the debugger I was also getting an "arithmetic overflow" error when calling GetDouble
on a field. As I looked further it turns out this field in the database table for
the given record had the value "-1.#IND". I'm not sure how that value got there but
once I delete the record the error went away. So essentially the "internal connection
fatal errror" exception was masking the root cause.
</p>
        <img width="0" height="0" src="http://blog.whconsult.com/aggbug.ashx?id=220306df-6140-4f05-ba3b-8b843c062cee" />
      </body>
      <title>Internal Connection Error Masks Root Cause</title>
      <guid isPermaLink="false">http://blog.whconsult.com/PermaLink,guid,220306df-6140-4f05-ba3b-8b843c062cee.aspx</guid>
      <link>http://blog.whconsult.com/2007/03/30/InternalConnectionErrorMasksRootCause.aspx</link>
      <pubDate>Fri, 30 Mar 2007 17:29:38 GMT</pubDate>
      <description>&lt;p&gt;
I'm using VS.NET 2003, SQL Server 2000.
&lt;/p&gt;
&lt;p&gt;
In my case, the error "internal connection fatal error" was being generated when using
a DataReader to read the field values of a record. As I stepped through the code in
the debugger I was also getting an "arithmetic overflow" error when calling GetDouble
on a field. As I looked further it turns out this field in the database table for
the given record had the value "-1.#IND". I'm not sure how that value got there but
once I delete the record the error went away. So essentially the "internal connection
fatal errror" exception was masking the root cause.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.whconsult.com/aggbug.ashx?id=220306df-6140-4f05-ba3b-8b843c062cee" /&gt;</description>
      <comments>http://blog.whconsult.com/CommentView,guid,220306df-6140-4f05-ba3b-8b843c062cee.aspx</comments>
      <category>ASP.NET</category>
      <category>SQL Server</category>
      <category>VS.NET</category>
    </item>
  </channel>
</rss>