Archive for the 'Coding' Category

Windows Update failing with XP SP3

After installing SP3, Windows Update kept failing when trying to install an IE7 update. I found this resolution.

Open a command line.

Type “Regsvr32 Wups2.dll” and hit enter.

The .dll will register with a confirmation pop-up.

No reboot is required.

Solution

ASP Net – Parser Error – Could not load type ‘xxx.global’

I started getting this error out of the blue and it was brutal. All dlls were compiled through VS 2008 and everything ran fine locally, but, as soon as I loaded the dll to the hosted server, the error appeared. I looked through hundreds of posts, but nothing would resolve the issue. I couldn’t even create a one page web site.

I ended up doing a fresh install on VS 2008 on a separate machine and that dll worked. I then did a XP repair on the initial machine and created a new user profile. Using the new profile, I could compile a dll that would work. When I logged into the old profile the error came back.

In this instance, something got screwed up in the initial profile that must have been causing a version conflict or some other issue. Not really sure how it happened, but I am glad it is over.

window.event has no value using href

I was calling a javascript function from the href property, but window.event was returning undefined.

When I rewrote the url using href=”javscript:void(0)” onclick=”js function”, this issue was resolved.

Set gridview header color in css

Setting a gridview header forecolor is pretty straight forward. One thing to keep in mind is that enabling sorting makes the header element = A, so you need to have an A class in your css.


.dgrHeader
{
color:Red;
text-align:left;
height:10px;
}
 
.dgrHeader a:link, .dgrHeader a:visited, .dgrHeader a:active
{
color:rgb(102,102,102);
text-align:left;
height:10px;
}


After your css is configured, you can either set the property programatically:

 
grdTemp.HeaderStyle.CssClass = "dgrHeader"

or in the grid itself:


<HeaderStyle CssClass="dgrheader" />

Collection was modified; enumeration operation may not execute.

Certain collections blow out when you use a for each loop, as the change in value results in the item dropping out of the collection.

This code resulted in the above error as it caused the CheckNodes collection to change.


For Each node As TreeNode In TreeView1.CheckedNodes
    node.Checked = False
Next

Re-writing the code as so works fine:


Dim y As Integer = TreeView1.CheckedNodes.Count
While y > 0
    TreeView1.CheckedNodes.Item(0).Checked = False
    y -= 1
End While

javascript debugging in VS 2008

If you want to step through your javascript code in VS 2008, be sure to add the js as a separate file, rather than inline. Unhandled js errors will still break to the error point, but breakpoints do not appear to function for inline js.

Convert RBG to hex

If you have ever tried to match a custom palette in Excel to hex codes, you know what a trial that can be.

Getting the Excel RBG is pretty simple: Tools / Options / Color / Modify / Custom.

Next, open up Microsoft Calculator under Accessories. Make sure the Dec radio button is checked, enter the R code and click the Hex radio button. Repeat for B and G and you have your hex code that now matches the Excel color exactly.

Detailed instructions

recreate designer.vb

After adding the AJAX control toolkit, the designer.vb page stopped staying in synch when I would add and delete controls.

Even though there were no compile errors and all the toolkit controls rendered fine in VS 2008, the designer file needed a reference to the AJAX toolkit in the project. I had only placed the reference in the actual page.

To regenerate designer.vb:

Delete the designer.vb page, right click on the aspx page and choose Convert to Web Application.

showModalDialog and ASP .Net

This type of error can get you wound up. I was using showModalDialog to open a new window and return values from a list. Every time I hit OK or Cancel, a new window would be spawned.

Turned out to be a simple fix. Just add the line below into the <HEAD> section of the page being opened.

<base target=_self>

.Net treeview selecting nodes

The treeview control has a lot going for it, but it is lacking any sort of ability to maintain state of the currently selected node. This becomes an issue when you want to change/maintain a property on a selected node.

An example would be a treeview of urls where you want to set the backcolor of the selected node after navigating to the new page.

The only way I found to resolve this issue is to store the node.valuepath in a session variable and reselect it during the page_load event.

First, make sure none of your urls are in the NavigateUrl property. This puts the treeview into “Navigation” mode and results in the OnSelectedNodeChanged event not firing. Urls go in the Value property.

Be sure to change your treeview PathSeparator to something like “|” or something other than the default “/”. If you forget to change the default value, it will cause all sorts of problems when using FindNode.

Next, add some code to catch the selectednode.valuepath


Private Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged
Session("selected") = TreeView1.SelectedNode.ValuePath
Response.Redirect(TreeView1.SelectedNode.Value, "false")
End Sub

Finally, add code to the pageload or init event:


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("selected") <> "" Then
TreeView1.FindNode(Session("selected")).Select()
End If
End Sub

Multiple IIS sites on XP Pro

You can configure multiple IIS sites in XP Pro, but you can only have one running at a time. Not sure why the MMC won’t let you do it, but there is an easy work around.

From the \Inetpub\Adminscripts directory

Find out what the highest numbered site is:

adsutil.vbs ENUM /P W3SVC

To create a new site:

adsutil.vbs COPY W3SVC/1 W3SVC/x

where x is the # of the new site

Here are the detailed instructions.

I have found this to be useful when testing .Net apps without wanting to launch studio.

ObjectDataSource configuration

When you have a gridview bound to an ObjectDataSource, you have to be sure to pass the fields defined in the gridview’s DataKeyNames section to your Delete and Update methods.

Otherwise, you will get an error similar to:

ObjectDataSource 'objDSStatus' could not find a non-generic method 'DeleteContactStatus' that has parameters: ContactStatusId, ContactStatusTypeId.

In this instance I had DataKeyNames=”ContactStatusId, ContactStatusTypeId”, but the DeleteContactStatus method only contained ContactStatusId – the actual primary key.

Also be sure OldValuesParameterFormatString=”{0}”

You don’t need to configure the DeleteParameters in the ObjectDataSource properties as the defined DataKeyNames are passed automatically.

Here is the update code that worked:

  1. Public Sub DeleteContactStatus(_
  2. ByVal ContactStatusId As Integer, _
  3. ByVal ContactStatusTypeId As Integer)
  4.  
  5. Dim arrParams(0) As SqlParameter
  6.  
  7. arrParams(0) = New SqlParameter("@iContactStatusId", ContactStatusId)
  8.  
  9. strSql = "Delete From ContactStatus " & _
  10. "Where ContactStatusId = @iContactStatusId"
  11.  
  12. SqlHelper.ExecuteNonQuery(cn, CommandType.Text, strSql, arrParams)
  13. End Sub

Unrecognized tag prefix or device filter

While working with VS 2008, I was getting this warning all through my asp .net code in addition to having no intellisense for any asp controls.

If I added the tag to my child pages, intellisense would come back. I saw a lot of other posts relating to VS 2005 which said to keep the master page open, but that didn’t work.

I had to do the following to get intellisense back:

1. Remove the masterPagefile setting in web.config

2 Delete everything from C:\Documents and Settings\[Username]\ApplicationData\Microsoft\VisualStudio\9.0\ReflectedSchemas

3. Add MasterPageFile=”[master page file name]” to the top of each child page.

Show “Start Page” in VS 2008

View / Other Windows / Start Page

Remove Compress Old Files from Disk Cleanup

An oldie, but a goodie. Whenever I build a new box, I seem to forget all the tweaks I have added.

This tweak gets rid of the annoying Compress old files process when you first start a disk cleanup.

Remove the Compress Old Files Key under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches

Here is the detail from Microsoft.

web.config and WebConfigurationManager

The 2.0 framework obsoletes many methods from 1.1.

A line like:

System.Configuration.ConfigurationSettings.AppSettings(“DocumentDirectory”)

results in a compiler warning.

Public Shared ReadOnly Property AppSettings() As System.Collections.Specialized.NameValueCollection' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'.

The new method is in the System.Web.Configuration namespace and is called WebConfigurationManager.

WebConfigurationManager.AppSettings(“DocumentDirectory”)

CSS items shows up as errors

After I brought a css file in as a theme, I ended up with dozens of errors on a rebuild. Even though HTML/CSS validation was set to Warning in Options, I had to uncheck the option, close the dialog, re-open the dialog, re-check, then re-start VS. CSS issues now no longer prevent a build.

Detailed description and screen shots can be found here:

http://www.west-wind.com/WebLog/posts/194167.aspx

Download files in ASP .Net

This is a useful function for downloading files. I use it a lot when downloading files from protected directories.

  1. Public Shared Function DownloadFile( _
  2. ByVal Server As HttpServerUtility, _
  3. ByVal Response As HttpResponse, _
  4. ByVal strFileName As String) As Boolean
  5.  
  6. Const adTypeBinary = 1
  7. Dim strSql As String
  8. Dim strFilePath, strFileSize, strDownloadFileName, strFileType As String
  9. Dim objFileInfo As FileInfo
  10.  

Remove HTML tags

RegEx can be a bit complex, but it sure can do a lot with just a few params. This function will strip all html tags in a string and return the enclosed data. | is the default delimiter.

  1. Public Shared Function RemoveHTMLTags( _
  2. ByVal strText As String, _
  3. Optional ByVal strDelimiter As String = "|") _
  4. As String
  5.  
  6. Return Regex.Replace(strText, "<(.|\n)+?>", strDelimiter)
  7. End Function
  8.  
  9. strData = RemoveHTMLTags("<td>1</td><td>2</td><td>3</td>")
  10.  
  11. strData equals "1|2|3"

Disabling comments in WordPress

I found the “No Comments” link on my WordPress site to be a bit annoying. Disabling comments is easy enough under Options / Discussion, but I wanted to remove the actual links from the page.

This proved pretty easy. You just need to edit comments.php and index .php and comment out the following line:

comments_popup_link('No Comments »', '1 Comment »', '% Comments »');

« Previous PageNext Page »