Sunday, October 21, 2007
Wednesday, April 11, 2007
DataBinding to RowError in a DataTable
In ASP.NET, sometimes we need to bind to the RowError from an ADO.NET DataSet. You might do this to support partial committed updates, for example, and report errors on records that did not work.
<asp:label id="RowError" text="'<%# GetDataItem().Row.RowError %>" runat="server">'></asp:label>
We have to do it this way because DataRow and DataRowView have special logic. In particular, references to them are resolved to their collection of items, and not to the DataRow or DataRowView itself. This is so you can have a column named RowError, which albeit stupid if you're using ASP.NET, could actually happen in the real world.
So what we do is GetDataItem (the syntax shown is VB.NET -- but should be easily adapted to C#, Chrome, Python, Lisp, Fortran, Cobal or whtever you are actually using). That returns the DataRow / DataRowView itself. Since I use a DV, I get a DataRowView, and have to go up to the real row (the Row property). Then, I pull the RowError property.
The point is understanding why something is wrong, and what tools you hae to fix it. Bind expressions are translated into calls to DataBinder. GetDataItem returns the item being used for binding data, so that you can access any arbitrary property. Otherwise, the object can (through various mechanisms) override DataBinding to make it "easier" on users of the class.
Monday, February 26, 2007
URI Parsing in IE7
Tuesday, February 13, 2007
JSON vs XML
<data> <table1> <col1>value1</col1> </table1> </data>They say this is the equivalent JSON: ({ "data" : { "table1" : { "col1": "value1"; } } }) Now the problem is that JavaScript isn't equivalent to the XML shown, instead it is equivalent to this XML: <data> <table1 col1="value1"> </data> The original XML has an object for col1, which serves as an extension point. In this case, clearly, no extension point is required and there is no advantage to having col1 as a child element versus having it as an attribute. If you use attribute-based XML, the resultant data is often smaller -- not larger -- than the JSON equivalent, and it is perfectly valid to use attribute based XML. For example, if you look at an HTML document: <div id="'123456'" name="'someName'"></div> A div is a container, so it must be an element. The properties of the element are listed inline, as attributes. They don't serve as extension points, and they aren't containers, so they are attributes (and not subelements). That is the same approach that should be taken in XML. Unless the data is either an extension point or a container, then it should be an attribute, not an element. HTML, XHTML, WordML, and ExcelML all provide examples of how to accomplish this. Conversely, object is an extension point -- with object, you have parameters which themselves might be markup fragments: <obeject class='blah'> <param name='param1'></param> </object> Here, you need the extension point. The issue with comparing JSON to element based XML is that element based XML ought to be the exception, not the rule. When you compare JSON and attribute based XML, what you find is that at about 20-30 records of data, the attribute based XML becomes smaller -- not larger -- than the JSON. At about 100 to 1000 records of data, the attribute-based XML is substantially smaller. There are contrived test cases that can counter this for specific data sets; the way I make this determination is simple. I have a "Ajax" HTTP Handler in .NET, and when I make a URL for a script block, I tell it whether I want that particular wrapper to be JSON, Element XML or Attribute XML. And it then does the rest. During testing phases of a web application, I try all the settings while using a proxy such as Fiddler that can tell you what the request sizes are looking like, and I simply look where for common use cases it is better. The other concern about JSON is the use of eval -- injection attacks are possible against eval from mixed data sources, even when getting the data from a known secure server. Eval, among other things, decodes HTML entities, and if you aren't alert for that, you can easily break out of the eval and manipulate the page. What people are less knowledgable about is that JSON that breaks out this way isn't limited to just communicating with the hosting server. No browser limits Image, IFrame, CSS, and other HTML elements in any way. You can create a form in a hidden IFrame (for example), point it towards any arbitrary web server, and do a submit, and only the invisible IFrame will update! Yes, I have a problem with using eval for anything that might come from any database. I think it is just begging for problems. You add a JSON parser in there, and anything you might have gained in per-request size is lost.
nVidia Saga comes to a close
Sunday, February 04, 2007
Vista, nForce 3 and never another nVidia product -- ever
Tuesday, August 08, 2006
Printing and IE 7
.NET Work Around
Friday, July 07, 2006
Registry and NetRefactor
Tuesday, June 20, 2006
HOWTO: Simulate "keep together" in IE
function test()
{
var blocks = document.all["content"].childNodes;
var currentPage = document.createElement("div");
currentPage.className = "page";
document.all.pages.appendChild(currentPage);
var content = document.all["content"];
while (content.childNodes.length > 0)
{
var block = content.childNodes[0];
currentPage.appendChild(block);
var pageTop = currentPage.offsetTop;
var pageBottom = pageTop + currentPage.offsetHeight;
var blockTop = block.offsetTop + pageTop;
var blockBottom = blockTop + block.offsetHeight;
block.blockTop = blockTop;
block.blockBottom = blockBottom;
currentPage.pageTop = pageTop;
currentPage.pageBottom = pageBottom;
currentPage.pageHeight = currentPage.offsetHeight;
if (blockBottom >= pageBottom)
{
currentPage = document.createElement("div");
currentPage.className = "page";
document.all.pages.appendChild(currentPage);
currentPage.appendChild(block);
block.className = block.className + " newpage";
}
}
}
test();
This is very IE specific right now, and I appologize for that if you are a FireFox user. As I said, I'll work up a more generic one later on.
The script takes block level elements from the "content" div and moves them one at a time into a new "page" div. The page div is formatted like this for screen:
.page
{ height: 11in; width: 8.5in; border: 2px solid black; display: inline-block; overflow: hidden; padding: .5in; page-break-after: auto; }
For print media, the following rule is added as well:
@media print {
.page
{ border: none; padding: 0px; }
}
For debugging purposes, I add the "newpage" class to the first block on each page -- this could as easily do other things. I also stash some values that I can view with the IE Developer Toolbar for debugging purposes.
Thursday, May 04, 2006
Printing from CSS
Monday, April 24, 2006
.NET Development
Class CertPolicy
Implements ICertificatePolicy
Const CertVALIDITYPERIODNESTING As Long = 2148204802
Const CertROLE As Long = 2148204803
Const CertPATHLENCONST As Long = 2148204804
Const CertCRITICAL As Long = 2148204805
Const CertPURPOSE As Long = 2148204806
Const CertISSUERCHAINING As Long = 2148204807
Const CertMALFORMED As Long = 2148204808
Const CertCHAINING As Long = 2148204810
Const CertREVOKED As Long = 2148204812
Const CertUNTRUSTEDTESTROOT As Long = 2148204813
Const CertREVOCATION_FAILURE As Long = 2148204814
Const CertWRONG_USAGE As Long = 2148204816
Const CertUNTRUSTEDCA As Long = 2148204818
Const CertCN_NO_MATCH As Long = 2148204815
Const CertEXPIRED As Long = 2148204801
Const CertUNTRUSTEDROOT As Long = 2148204809
Private m_FT As FilteredTable
Public Sub New(ByVal FT As FilteredTable)
m_FT = FT
End Sub
Public Sub New()
End Sub
Private m_AllowExpired As Boolean = True
Private m_AllowUntrustedCA As Boolean = False
Private m_AllowBadName As Boolean = False
Public Property AllowUntrustedCA() As Boolean
Get
Return m_AllowUntrustedCA
End Get
Set(ByVal Value As Boolean)
m_AllowUntrustedCA = Value
End Set
End Property
Public Property AllowBadName() As Boolean
Get
Return m_AllowBadName
End Get
Set(ByVal Value As Boolean)
m_AllowBadName = Value
End Set
End Property
Public Property AllowExpired() As Boolean
Get
Return m_AllowExpired
End Get
Set(ByVal Value As Boolean)
m_AllowExpired = True
End Set
End Property
Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult
' you can do your own certificate checking here
' you can get the error values from WinError.h, all the certificate errors start with Cert_
' we just return true so any certificate will work with this sample
Dim probLong As Long = CLng(certificateProblem)
Select Case probLong
Case CertEXPIRED
m_FT._ErrorMessage = " Cert is in invalid time"
Return AllowExpired
Case CertUNTRUSTEDCA
m_FT._ErrorMessage = "The CA is not trusted"
Return AllowUntrustedCA
Case CertUNTRUSTEDROOT
m_FT._ErrorMessage = "The certificate name is not match"
Return AllowBadName
Case 0
Return True
Case Else
m_FT._ErrorMessage = "Server Certificate has a problem (SSPI Code is " & certificateProblem & ")"
Return False
End Select
End Function
End Class
Friday, April 21, 2006
colgroup and ASP.NET
| Region / County / District | Data | ||
|---|---|---|---|
| Ohio | |||
| Ohio | Greene | ||
| Ohio | Greene | Xenia | |
| Ohio | Greene | Fairborn | |
| Ohio | Montgomery | ||
| Ohio | Montgomery | Dayton | |
| Ohio | Montgomery | Vandalia | |
The comment MSIE HTML Tag
Wednesday, April 19, 2006
The Float Model Problem
Microsoft is flouting nothing. When Microsoft originally implemented the CSS1 (note: they only claim CSS1 compatibility) features, there was no working reference implementation, there was one other browser with any CSS1 support, and that support was legendarily bad. Internet Explorer is derived from Mosaic (the notification is still there in the about box, as required to use Mosaic code base). Netscape's Mozilla engine, as it stood through Netscape 5's end-of-development, was a reimplementation of Mosaic by the same folks who implemented it originally. If you remember Netscape 4.7 (think way back), it didn't handle much of anything right. Even early versions of the open source Mozilla (I'm talking very early versions) could not successfully render CSS. Here's a theory for you -- Mosaic was written before CSS existed, and so it did not take the needs of CSS into account when it was designed. As Mosaic derivitives, both Netscape Navigator and Internet Explorer inherited this limitation. This was resolved in the Mozilla code base when the browser's rendering engine was rewritten from scratch, resulting in Gecko. The new engine, which was written after the CSS3 specification was at a draft status, and after the mistakes of the first implementation was performed, is what allowed full conformance. When you look at IE 7, it still is using the mosaic engine at its heart. Microsoft has rewritten probably all of the code at this point, but it still, at its heart, is the roughly the same rendering system that Netscape and the Mozilla.org team never could get to work properly. I do want to point out that Gecko has plenty of CSS bugs, some of which have been open for 3+ years, have patches, and have had implementation in the actual codebase blocked by commercial companies such as IBM and Novell. And no, I'm not kidding. It disgusts me that it is "evil" when Microsoft implements a draft standard, but when FireFox implements portions of it with proprietary extensions, and uses properties incompatible with the draft standard, it's hailed as a standard's machine. What we really need to do is force CSS implementations over to the XML dialect, so that vendors such as Mozilla and Microsoft can use standard XML+NS for their extensions, and can use standard XML+NS to indicate the draft specification to which they are compliant, so that user agents, web design tools, etc. can deliver content based on that draft standard. Note the big thing here is this... It took Mozilla, without the potential of breaking huge corporate accounts and millions of end users, more than two years to get to its current level of CSS support. Microsoft cannot afford to break existing huge commercial accounts, nor millions of end users, and so this task is magnified probably an order of magnitude for them.I am no purist, and could happily live with a specification designed by Microsoft, but to have MS publicly support the specs while silently flouting them really burns my toast. Is this how the future is made?
It's past time that these issues were aired out. Gentle reader, if you know any way of 'getting to' the movers and shakers at Microsoft, won't you please try and shake loose some kind of information regarding future plans? I dread having to tell the next newbie that the simple, straightfoward CSS standards can't simply be used 'as is', because the majority browser maker refuses to conform as it supposedly has agreed to do. This situation has got to end sometime; why can't it be now?
