Adsense

Monday, December 22, 2008

Databinding an asp:ListBox has no selected items (selected = false)

If you are working with a Data Bound ASP.Net ListBox control (or a similar control) and are having trouble with all of your ListItem.Selected calls are returning false even though you KNOW you selected one or more of them. You might have an issue with the way you're Data Binding.

Consider the following code. In my example I am using a DataBindControls method that will retrieve some data and then bind it to a ListBox.

private void DataBindControls() {
ArrayList roles = RoleProvider.Instance().GetRoles();

lbRoles.DataSource = roles;
lbRoles.DataTextField = "RoleName";
lbRoles.DataValueField = "RoleId";
lbRoles.DataBind();
}

I just so happen to be calling this method in the Page_Load even of my page. Unfortunately, I forgot to wrap this call in a "IsPostBack" check. What is happening is that my control is being databound again before I access the selected values from the previous request.

protected void Page_Load(object sender, EventArgs e) {
DataBindControls();
}

You can easily remedy this issue by wrapping the call in an if statement that makes sure to only databind your controls on the initial call to the page. (when it's not a post back)

protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
DataBindControls();
}
}

Just another one of those "Palm to Forhead" issues. Hope it helps someone. =)

Tuesday, October 14, 2008

Internet Explorer 6 (IE6) has extra white space gap after a empty, fixed size div with a background-image

I was trying to fix a small display issue with one of our pages in IE6. I had an unordered list that we set the background color on and wanted to add rounded images to the top and bottom to give it a nice look.

The rounded top image

storesubnav-selected-top

The HTML

<div class="container">
<
div style="height: 6px; width: 190px; background-image: url(../images/top.gif); background-repeat: no-repeat;">
</
div>
<
ul style="background-color:#763000;">
<
li><a href="#">Item 1</a></li>
<
li><a href="#">Item 2</a></li>
<
li><a href="#">Item 3</a></li>
</
ul>
<
div style="height: 6px; width: 190px; background-image: url(../images/bottom.gif); background-repeat: no-repeat;">
</
div>
</
div>

Simple enough. Everything works great in IE7, Firefox, Chrome, etc... I get a report of extra white space after the top rounded image. I track down a system running Windows XP with IE6 and I fire it up. Sure enough, a bit of white space after the top div. But why....

The Problem

With White Space

I tried everything that seemed to make sense. Checked margins, padding, etc... Everything was either good or changing it did nothing. Unfortunately in IE6 I didn't have access to my favorite tools like Firebug, so it was even more frustrating. Eventually I figured it out and I think I know what's going on.

IE6 assumes a font-size of 20px. Since my background-image was only 6px in height, when I set the height on the div it was ignored. The div would try to shrink to my set height, but would end up limited by the assumed font-size of 20px. By setting the font-size to something smaller in height than my desired 6px, it would solve the problem. Remember this when dealing with empty divs IE6. Hope it helps someone.

The HTML that works

By setting the font-size style in the "empty" div, IE6 allows the div to shrink to my desired height of 6px.

<div class="container">
<
div style="height: 6px; font-size:0em; width: 190px; background-image: url(../images/top.gif); background-repeat: no-repeat;">
</
div>
<
ul style="background-color:#763000;">
<
li><a href="#">Item 1</a></li>
<
li><a href="#">Item 2</a></li>
<
li><a href="#">Item 3</a></li>
</
ul>
<
div style="height: 6px; font-size:0em; width: 190px; background-image: url(../images/bottom.gif); background-repeat: no-repeat;">
</
div>
</
div>

Without White Space

Google's Chrome displays saved passwords in plain text

Google's new web browser "Chrome" is pretty nice. I used it for a full day and found quite a few things that I really liked about it. As soon as the few plug-ins that I use daily get equivalents in Chrome, I will possibly use it for every day use. I was sad to learn that one of my biggest web browser pet-peeves is present in Chrome, and it seems to be an even worse implementation of it than Firefox 3's (Firefox 3 Saved Password Security.)

The Saved Password feature of any browser can be invaluable. It saves a great deal of time for passwords that you would otherwise have to enter many times a day. Unfortunately, most web browser make it WAY too easy to gain access to the web site URL, username and plain-text passwords to your accounts. Someone with only a few minutes access to your machine can easily gain access to this information.

In Google's Chrome, all someone (with several seconds alone with your computer) needs to do to steal your information is...

  1. Open Chrome
  2. Click customize(the wrench)
  3. Select Option
  4. Click the Minor Tweaks tab
  5. Click Show saved passwords
  6. Select one of your "secure" sites
  7. Click Show password

Chrome

BAM! Someone just stole the web site address, username and password to one of your accounts? I hope it wasn't something important... In Firefox's defense, at least they have a "Master Password" that will require you to enter a password prior to them showing your passwords in plain-text. But no such feature is present in Chrome.

I'm always blown away by people's responses to this problem. People that I show in person are usually shocked when we're both staring at their bank account password in plain-text right before their eyes. People online usually say that no one ever has access to their computer, so their safe, or that they always lock their system when they're away. That's a great practice to get into, but I know the vast majority of users aren't so diligent.

At the very least, the Chrome team needs to add a master password for an added layer of security. I think both Firefox and Chrome should warn the user about this danger and prompt them to setup a master password by default, rather than having saved passwords turned on by default.

Tuesday, September 09, 2008

Reporting Services is grayed out after adding reporting services to an existing MS SQL install

You can add Reporting Services to an existing install of MS SQL in Windows Vista (not sure how different the step would be in XP) by following these steps.

  1. Open Programs and Features (press the windows key, type in Programs and Features and press enter)
  2. Right-Clicking on Microsoft SQL Server 2005  and click Change.
  3. Under SQL Server 2005 instances:  select the instance you want to add reporting services to and click Next
  4. Click on To install a new component, click here
  5. Browse to the Setup.exe file on your installation disk and click OK
  6. Click through the wizard until you get to the Components to Install screen
  7. Select Reporting Services  and finish the wizard.

It's that simple... Unless Reporting Services  happens to be Grayed Out. If this is the case for you, you are probably missing requirements that Reporting Services needs. During the above process, you came to a screen called System Configuration Check and you probably got a yellow exclamation point on IIS Feature Requirements. Basically, you need to add some features to your IIS installation before you can install reporting services.

 

To enable these IIS features, follow the steps below.

  1. Open Programs and Features (press the windows key, type in Programs and Features and press enter)
  2. Click on Turn Windows features on or off to bring up the Windows Features window
  3. Expand the Internet Information Services option and place check marks next to all the features you want to install
  4. Click OK to install the features.

Here is a list of features that are required before you can add Reporting Services to your existing MS SQL Server installation. (Reference here.)

Component Folder
Static Content Common HTTP Features
Default Document Common HTTP Features
HTTP Redirection Common HTTP Features
ASP.Net Application Development
ISAPI Extension Application Development
ISAPI Filters Application Development
Windows Authentication Security
IIS Metabase Management Tools
IIS 6 WMI Management Tools

 

After adding these features, try to perform the steps above for adding Reporting Services to an existing MS SQL Installation and Reporting Services should not be grayed out. Hope this helps.

Tuesday, August 19, 2008

How to Enable/Disabled Recording Devices in Windows Vista

I had some strange sounds coming over my speakers and thought it might be one of my recording devices (my built in mic, etc) acting up. To troubleshoot this I brought up the Sound window, clicked on the Recording Tab and right-clicked on each of my recording devices to disable them. It turns out my problem was caused by something else and was easily fixed, but now I have a new issue. How to I enable my recording devices. If you check the Recording Tab in the Sound window, there are no devices listed. Maybe I can enable them directly from the Device Manager. Nope, nothing listed there either...

The solution is fairly simple, but seems to be completely non-standard for windows. Go back to the Recording Tab in the Sound window and right-click in the now blank tab. You should get a context menu that has two options (Show Disabled Devices and Show Disconnected Devices.) Click on Show Disabled Devices and you should now be able to see and enable your devices.

Not a huge issue, but fairly annoying since it is done differently than most other places in Windows (i.e. The network device screen. Disabled devices are still visible but are disabled...)

Monday, August 11, 2008

How to Replace/Remove Blank/Empty Lines in Visual Studio using Regular Expressions

I'm mainly just posting this so that I don't forget it. I find myself needing this every now and again and need an easy place to find it. Hope it helps someone else. =)
If you want to remove or replace the Empty Lines in a Visual Studio file, you can perform the following.
  • Press Control + H on your keyboard to bring up the replace window.
  • In the Find What: field, enter ^$\n
  • In the Replace With: field, enter nothing
  • Check the Use: checkbox and then select Regular Expressions from the drop-down
  • Click Replace All
Note: If you want to remove the blank lines from just a part of your file, select/highlight it prior to performing the step above and make sure Selection is selected in the Look in: field.
Hope this helped. =)

Thursday, July 10, 2008

Firefox shows saved passwords in plain text!

I finally got around to updating to Firefox 3 yesterday. With all the new features being touted around the web, I was hoping that they would have gotten around to addressing my biggest pet-peeve with the browser. It seems that they didn't! You can read my original post about this issue HERE. Firefox 2 - Saved Password Security.

I'm sure you are diligent about security. Every time you get up to take a walk, hit the restroom or refill your <Insert the caffeinated beverage of your choice>, you always hit [Windows + L] to lock windows. You then leave your system, secure in the knowledge that all your secrets are safe and secure while you're away. What's that?!? You NEVER lock your computer when away from it...? If this is you, and you use Firefox as your main browser, this post might be of great interest.

When you install Firefox and log into a web site, such as MySpace, you might get a popup asking if you would like Firefox to save your password for you. What a great idea. If I let Firefox remember my passwords, I wont have to remember and enter them every time I visit a site. Handy! Better yet, this feature is turned on by default. Thanks Firefox. I, like most of you, probably just assume that my passwords are being handled securely and continue using Firefox for months adding more and more passwords to Firefox for my favorite sites as I go.

How secure are my saved passwords in Firefox 3?

In Firefox 3, it looks something like this.

myspace

You try to sign into your favorite Social Network. MySpace in this case.

Remember

Firefox is so helpful. Sure! Remember my MySpace password.

security

What exactly happens with my MySpace passwords in Firefox 3? They're secure, right? You can click [Tools > Options > Security (Tab) > Saved Passwords] to find out.

password

Well, Well. What do we have here? The URL to the web site and my username. Seems harmless enough. But what's this? A [Show Passwords] button? Lets click it and see what happens...

show

Gulp. There it is. Everything that someone would need to log into my MySpace account. The site address, my username, and my password in PLAIN TEXT! Anyone with about 20 seconds alone with your computer could easily get this information for themselves.

Try it for yourself and see just how scary it is when you see all the passwords for your banking accounts, your E-Trade account, etc. Better yet, walk your friends and co-workers through this on their own workstations and see the shock on their faces when they see their PLAIN TEXT passwords visible to the world in 3 easy steps that take 10 seconds to perform. I've gotten some pretty startled expressions showing people this.

I definitely think that Firefox should have the Master Password functionality enabled by default and should show the user a warning the first time they try to save a password. It seems like such an innocent thing, but having access to passwords in Plain Text is bad in my opinion.

How to protect yourself

Option 1. Turn off the "Remember passwords for sites" feature on the Tools > Options > Security Tab

Option 2. You can actually protect yourself from this flaw pretty easily, but it makes the feature a tad-bit more annoying. There is a "Use a master password" checkbox on the Security Tab too. If you check this box, you will be required to supply a password to be able to view saved passwords, or before you can use them to log into any web sites. Definitely worth it in my opinion even if the chance of someone having access to your workstation is slim.

Option 3. You should really consider locking your workstation when you are away from it anyway. If this isn't a habit that you already have, its really not that hard to start now. Just press the [Windows Key + L] to lock windows before you leave your computer.

Disclaimer

I'm always torn about writing about this kind of thing. Most of you will use the information to protect yourself, your friends and your co-workers. If nothing else, I've always felt that it is better to be aware of something even if a small percentage of people will use it negatively. For those of you thinking of using this to STEAL other people's passwords. Shame On You!

Just to save you a few seconds of attempting to log into my MySpace account. The email address, user names and passwords in the screen shots above have been altered to protect the innocent. =)

Monday, June 02, 2008

MSDTC on server 'SERVER NAME' is unavailable

MSDTC Error

You might encounter this error when trying to interact with a Microsoft SQL Server whose hosting environment doesn't have the Distributed Transaction Coordinator service turned on. To correct this problem, turn on the Distributed Transaction Coordinator service on the server hosting your SQL Server instance using the following steps.

  1. Press your 'Windows Key + R' to bring up the run window
  2. Enter 'Services.msc' in the run box and press ENTER
  3. Look for the service named 'Distributed Transaction Coordinator' and right click on it.
  4. Click on 'Start'

Services

The service should now be started, and if the SQL Gods smile upon you, your error should be gone.

Tuesday, May 27, 2008

How to Sort a generic IList or List

A while back I wrote a post on How to sort a Generic IList. Here is another approach.
To sort a generic List<T>, you can create a class that implements IComparer<T> and tells the list how to sort itself. Its fairly straight forward and the example below shows how to sort Widgets.
A Widget is a simple class that has a public string Name and a public int Size. I want to be able to sort generic lists of widgets (List<Widget>) by name and by size. You can see my code below.
The widget and sorter implementations
public class Widget {
    public string Name = string.Empty;
    public int Size = 0;

    public Widget(string name, int size) {
this.Name = name;
this.Size = size;
}
}

public class WidgetNameSorter : IComparer<Widget> {
    public int Compare(Widget x, Widget y) {
        return x.Name.CompareTo(y.Name);
}
}

public class WidgetSizeSorter : IComparer<Widget> {
    public int Compare(Widget x, Widget y) {
return x.Size.CompareTo(y.Size);
}
}
And application to create the list and sort it
class Program {
static void Main(string[] args) {
List<Widget> widgets = new List<Widget>();
widgets.Add(new Widget("Zeta", 6));
widgets.Add(new Widget("Beta", 3));
widgets.Add(new Widget("Alpha", 9));

OutputWidgets(widgets);
widgets.Sort(new WidgetNameSorter());
OutputWidgets(widgets);
widgets.Sort(new WidgetSizeSorter());
OutputWidgets(widgets);

Console.ReadLine();
}

public static void OutputWidgets(List<Widget> widgets) {
foreach (Widget w in widgets) {
Console.WriteLine(string.Format("{0} - {1}", w.Name, w.Size));
}
Console.WriteLine(string.Empty);
}
}
Running the application above results in the following output.
output
Straight forward enough? =)
So what do you do if you have a generic IList<T> and want to sort it? Since you only have the interface reference that can't make assumptions about what's implementing it, you have no Sort method. You can use the ToList() method to convert the IList<T> into a List<T>, and then call the Sort() method. See the updated example below. (Note: I previously blogged about a way to sort a generic IList using the ArrayList.Adapter. You can read about it HERE.)
class Program {
static void Main(string[] args) {
IList<Widget> widgets = new List<Widget>();

widgets.Add(new Widget("Zeta", 6));
widgets.Add(new Widget("Beta", 3));
widgets.Add(new Widget("Alpha", 9));

OutputWidgets(widgets);
widgets.ToList().Sort(new WidgetNameSorter());
OutputWidgets(widgets);
widgets.ToList().Sort(new WidgetSizeSorter());
OutputWidgets(widgets);

Console.ReadLine();
}

public static void OutputWidgets(IList<Widget> widgets) {
OutputWidgets(widgets.ToList());
}

public static void OutputWidgets(List<Widget> widgets) {
foreach (Widget w in widgets) {
Console.WriteLine(string.Format("{0} - {1}", w.Name, w.Size));
}
Console.WriteLine(string.Empty);
}
}

Saturday, March 08, 2008

How To Fix Dead/Stuck Pixels on a Playstation Portable (PSP)

So, I broke down and bought a Playstation Portable (PSP) this weekend. Lo and behold, it has a single stuck pixel. I didn't even notice it until I fired up a game for the first time, but there it is... A little, constantly red, annoying little bastard!

I really hate confronting retailers with returns, especially when its a single pixel that I'm complaining about. This wouldn't be the first time that I've done it though. But before I packed the PSP back up and headed for Best Buy, I figured I'd check online to see if this was a common problem. Unfortunately, it is a very common problem with PSPs and many people that have exchanged a PSP due to dead pixels, reports that their new unit has even more. So I count myself somewhat lucky to only have a single stuck pixel.

Luckily, I happened upon a post that talked about a little movie that that was originally distributed to help fix dead/stuck pixels on LCD TVs and monitors. The video is a series of screen that flash repeatedly in each of the colors that a pixel supports (Red, Greed, Blue.) The idea being that you can coax a stubbornly stuck pixel into working (or raise a dead pixel from the grave) by constantly forcing all of the pixels of the display to cycle through all of their possible states. (great idea!)

(Note: A stuck pixel is a pixel that only displays a single color (red in my case) and doesn't cycle to any other color. A dead pixel is a pixel that is black and never displays a color. The success rate seems to be higher with stuck pixels over dead ones.)

I downloaded the PSP version and have it currently running on my PSP, but some people have reported success in minutes, while other have had to let the video run for several hours. The consensus seems to be, that if the video doesn't fix your stuck/dead pixel in 24 hours, you might just be stuck with it.

I post this here, because I know of a lot of people that have stuck/dead pixels on their LCD monitors or laptop screen, and I figure that this might be worth a try on those as well. I'll post a follow up and let everyone know how it worked on my PSP. =)

You can download the movie file here, and read about it here.

Good luck and let me know if it works for you (especially when not used on a PSP.)

UPDATE

Well, I ran the video for probably 7 hours on my new PSP with no luck. The red little bastard pixel remained. Luckily, Best Buy was great at letting me return my unit for a new one. And I haven't been able to find any other stuck/dead pixels.

Hope you have better luck.


Thursday, March 06, 2008

'Logon failure: unknown user name or bad password.' message in Windows Vista on a Dell D830 with a Fingerprint Scanner and Embassy Security Center. Bl

I received a new laptop for work (a Dell D830) and had a fairly easy time getting it setup for development. To my dismay, I notice periodic Blue Screens of Death (BSOD) while booting into Windows Vista. I looked up the error codes and was unable to find a cause and since my system always seemed to boot normally the next time.

Talking with a co-worker of mine that got a new laptop when I did, we both experienced seemingly random BSODs and were always a bit suspect of the Fingerprint scanner. I didn't really worry about it too much. That is, until this morning.

While booting this morning, I got another BSOD. When my system booted again, I was unable to logon to Windows Vista. Every time I would put in my username and password I would get the following error message.

"Logon failure: unknown user name or bad password."

I also noticed that I wasn't given the option to use my D830's Fingerprint scanner to logon either. I tried logging onto domain accounts and local account with no luck. I rebooted multiple times. I used Vistas startup repair tool with no luck. It was looking like I might have to hit a restore point or restore an image of my laptop.

Luckily for me, my boss had experienced a similar issue. The fix is a mixture of disabling your Fingerprint scanner and Dell's Embassy Security Center. The first step is to boot into Safe Mode by pressing F8 before windows boots and selecting it from the boot menu. You should be able to logon to windows in safe mode (if not, you might have a different issue.) Once you are logged on, perform the following.

Disable the Fingerprint scanner

(this step might be optional, since the second step might do it automatically.)
  1. Press your Windows Key and type "Device Manager" and hit Enter to bring up the device manager.
  2. Under Biometrics, right click on your fingerprint scanner and select Disable
  3. Close the device manager

Turn off Secure Windows Login in Embassy Security Center

  1. Press your Windows Key and type "Embassy Security Center" and press Enter (if you don't have this application, you probably have a different issue going on.)
  2. Click on Windows Logon
  3. Uncheck Enable Secure Windows Logon
  4. Click Apply and close Embassy Security Center

After performing these steps, reboot your machine normally and try to login again. Worked great for us on our Dell D830 and was a bit of a pain to track down. I might post an update and let you know if this also clears up my random BSODs.

Hope this helps someone. =)

Wednesday, February 27, 2008

How To safely shutdown and restart Windows Explorer (Explorer.exe) in Windows Vista

There are few things more frustrating than having Windows Explorer (Explorer.exe) FUBAR while you're working or playing in windows (not to mention when it crashes completely and unexpectedly.) If you ever find yourself in a situation where you want to restart the explorer process, you can follow these steps to restart it in a safe manner.

Step 1. Shutdown Windows Explorer

  • Click on the start button
  • Press and hold Ctrl+Shift then Right-Click on a blank spot on the start menu

right-click

  • You should see the following dialog. Click on Exit Explorer

dialog

Step 2. Restart Windows Explorer

  • Open the task manager by pressing the ctrl+shift+esc keys
  • Click on File > New Task(Run)
  • Enter Explorer next to Open: and press Enter

This process will safely shutdown and then restart the Windows Explorer process.

Wednesday, January 30, 2008

Samsung Blackjack - Windows Mobile 6 - FINALLY!

I clearly remember the salesman telling me that I should be able to download and install Windows Mobile 6 "AS SOON AS ITS RELEASED" onto my sleek new Blackjack last fall when I purchased it. After many months, a million false alarms, several leaked versions of WM6, I finally have an official version installed on my Blackjack.

Get the OFFICIAL release from Samsung below, and Enjoy!

Get Windows Mobile 6 for your Black Jack!

Detailed Update Information

  • Microsoft Windows Mobile 6.0
  • Microsoft Office Mobile (allows you to view & edit XLS and DOC files on the fly)
  • Video Share Calling Technology (allows you with supported plan and devices, to transmit live or recorded video to a recipient)
  • TeleNav & MobiTV capable
  • Modified UI with updated text & icons in several areas
  • Enhancements to improve call quality
  • Fixed, Contact lookup doesn’t work when saving embedded SMS phone number
  • Fixed, Several Bluetooth issues
  • Fixed, VCML count not displayed properly
  • Fixed, Media player issue
  • Fixed, Embedded URL in MMS could not be saved
  • Fixed, CV does not play in full screen mode
  • Fixed, Converter for currency now supports Canada
  • Fixed, Handset would sound tone when charger was inserted in Silent Mode
  • Integrated Daylight Savings Time Patch
  • Enhanced international roaming support (originally included in GB4 S/W)

Monday, January 21, 2008

"Error: SQL Server does not exist or access denied" - SQL Server 2005 - .Net 1.1 - Specifying ip,port

I recently picked up a project that was written using Visual Studio 2003 and .Net 1.1. The application connects to a SQL Server 2005 database, and I didn't have the connection string that was used previously and had to create my own. I added a ConnectionString key to the appSettings section of my App.config, and fired her up. The connection string pointed to a freshly generated copy of the database needed for the application. After a few seconds, I was presented with the following error "Error: SQL Server does not exist or access denied". Joy.

Because this error is so generic, there is a lot of information returned by Googling the message. Unfortunately there are a million things that might be the cause. I couldn't find a solution online, but ended up finding a fix for my specific situation.

If you are working with a project created using .Net Framework version 1.1, against a SQL Server 2005 DB, and trying to connect without specifying the ip and port of your db engined, you might get this error. What you might want to try is to replace your "data source" with the "ip,port" of your db engine and see if it fixes your issue.

OLD/Broken: <add key="ConnectionString" value="data source=.; initial catalog=YourDB; user id=YourUsr; password=YourPwd;" />

NEW/Working: <add key="ConnectionString" value="data source=127.0.0.1,1433; initial catalog=YourDB; user id=YourUsr; password=YourPwd;" />

Just one more thing to try when dealing with this very generic Error Message.