Posts
16
Comments
96
Trackbacks
18
May 2006 Entries
Less than useful helpfiles, part 1

In the helps for HtmlInputControl.Name (for .NET 2.0):

Gets or sets the unique identifier name for the HtmlInputControl control.

Later on, in that same help file:

In this implementation, the get accessor returns the value of the Control.UniqueID property. However, the set accessor does not assign a value to this property.

So then why say that it sets the property, if it doesn't actually set the property?

posted @ Tuesday, May 09, 2006 1:37 PM | Feedback (1)
Repeaters, Checkboxes and UpdatePanels, Oh My!

I was working on some sample stuff that I'll be posting later and ran into a problem. I had 2 different update panels; inside one was just a div, inside the other one was a repeater. Inside the repeater I had a bunch of checkboxes, and when I checked/unchecked them, I needed the first update panel to be updated. This posed a couple of problems:

  • A checkbox doesn't have a CommandName property, and can't be used to trigger a Repeater's ItemCommand event

This I got around by declaring the event handler for the checkbox in the markup: OnCheckedChanged=”myCB_OnCheckedChanged”, and in the event handler I can cast the sender argument to a checkbox. The other problem:

  • An UpdatePanel's list of triggers can't include a control that's inside a template

Which means I can't say <atlas:ControlEventTrigger ControlID=”myCB” EventName=”myCB_OnCheckedChanged” />, since myCB doesn't actually exist at runtime. Instead, in myCB_OnCheckedChanged, I can just say: updatePanel1.Update(); and everything works fine.

Hope this helps...

posted @ Monday, May 08, 2006 2:08 PM | Feedback (3)
Retrieivng data from XML inside SQL

Recently I had to retrieve some data from SQL that was tucked away inside XML. We have a “Settings” class inside our application that is a bunch of public properties, which we then serialize to XML to store inside the DB. This lets us easily add/remove fields to store without having to modify the database.

This can be a problem if you need to access those one of those field values from within SQL, but SQL 2005 provides some methods to do this (note that your data column must be the xml data type, I haven't found a way to get this to work by casting an ntext field to xml):

Providing your class looks like this:

[XmlSerializable]
public class GlobalSettings
{
  [XmlElement]
  public int SomeValue;
}

Then when serialized, your XML will look similar to this:

<GlobalSettings>
  <SomeValue>5</SomeValue>
</GlobalSettings>

In SQL Management studio, you can write this (assuming GlobalSettings is the table and GlobalSettingsXML is the column where this data is stored):

SELECT GlobalSettingsXML.query('(/GlobalSettings/SomeValue)') FROM GlobalSettings

This will return:

<SomeValue>5</SomeValue>

Which may not be as useful as we want. :) To get the actual value (5) from this, we need to use the value() function:

SELECT GlobalSettingsXML.value('(/GlobalSettings/SomeValue)[1]', 'int') FROM GlobalSettings

This will give us '5', cast to an int. Per the MSDN helps on value(), the [1] is required after your xpath expression because the expression is supposed to return a singleton. I'm not quite sure what that means or how the [1] denotes it, but it works (if you know, by all means tell me!).

Hopefully this will be of use to you.

 


 

posted @ Wednesday, May 03, 2006 1:07 PM | Feedback (0)
News