RadicalWacko January 29th, 2009
I just ran into an irritating little problem with using TryParse when assigning to nullable object. The following is the code I was using to assign a value from a ASP.NET dropdown list to a nullable Int32 variable:
If Int32.TryParse(ddlExample.SelectedValue, testobj.TestNullableInt32 )Then
testobj.TestDescription = ddlExample.SelectedItem.Text
End If
Apparently, TryParse actually attempts to access the value of the object to which it attempts to assign the parsed value which can cause an InvalidOperationException when it attempts to retrieve the value of the nullable object. So make sure to assign the parsed value to a regular type before assigning it to a nullable object. Oh yeah, I know it’s VB.NET code, but I do what the client wants.
RadicalWacko March 24th, 2008
I recently had a task in one of my current projects that required me to extract the authentication mode of the current solution’s web.config file. The only was I figured out how to do it was by parsing the XML of the file by hand as shown below (Yeah, I know, it’s VB.NET. I do what the client wants.):
Dim config As New System.Xml.XmlDocument()
config.Load(Server.MapPath("\Web.config"))
Dim authMode As System.Xml.XmlNode = config.SelectSingleNode("/configuration/system.web/authentication/@mode")
Return authMode.Value
While that works just fine, it seems a little primitive and I figured Microsoft would have introduced a library to get that kind of data. Anyone know of any?
RadicalWacko March 23rd, 2008
I’ve decided to start posting the solutions I find in irritating little problems that take me forever to find. Some of these will probably be obvious, but hopefully it might save someone’s time. My current problem was that I had a DotNetNuke module that was sitting in a AJAX Update Panel. I needed to set the focus to a particular control based upon a post back click on a radio button. The standard focus() method didn’t work and neither did the old fashioned RegisterClientScriptBlock stuff with a provided JavaScript function. Turns out there is an extremely easy way to do this which is to use the ScriptManager SetFocus method using the base Page for the control as shown below:
ScriptManager.GetCurrent(Me.Page).SetFocus(txtApplicationDate)
Hope that helps someone.