Tuesday, July 13, 2010

I ran into a situation where I needed to know what control was gaining focus in the Leave() event of another control.  The situation I was working with is as follows;  I have a multi-line text box that when it gains focus I want a listview of potential values to popup below it.  When the textbox loses focus, the listview should be hidden.   The user should be able to click on the listview to select items to input into the textbox.  The problem was when the user clicked on the listview, the textbox lost focus and was hiding the listview. 

 

Enter the ActiveControl property on the form.  This handy property allows me to check, in the Leave() event, what is the new active control with focus.  Thus I can check to see if the textbox lost the focus to the listview control and if so, skip the hiding of it. 

 

Here we have the textbox named txtComplaint, when it gets the focus we make listView visible.

 

private void txtComplaint_Enter(object sender, System.EventArgs e)
{
  listView.Visible = true;
}

 

When the textbox loses focus we see if the ActiveControl is the listView, if not we hide it.

private void txtComplaint_Leave(object sender, System.EventArgs e)
{
  if (ActiveControl.Name != "listView")
    treeComplaint.Visible = false;
}
Tuesday, July 13, 2010 3:56:56 PM (Eastern Daylight Time, UTC-04:00) | Comments [0] | .NET | Code#
Wednesday, March 11, 2009
This was an interesting problem I ran into today. Suddenly whenever trying to debug an ASP.Net project, I was getting a Page Not Found error from the browser. What gives? It worked this morning!! What had I done? I installed some windows updates that had been waiting for me while I ate lunch.

What was the problem? Well it seems that an update for windows defender caused the hosts file entry for localhost to stop working.

What was the fix? Add the line 127.0.0.1 localhost to the end of your host file....all seems well now.

Some more discussions here

Wednesday, March 11, 2009 2:35:38 PM (Eastern Daylight Time, UTC-04:00) | Comments [0] | .NET#
Saturday, November 03, 2007

I've recently started playing with SubSonic on a new project.  My first few attempts at generating code failed.  The files were being generated, but they contained no code.  I'm sure it states it clearly somewhere but I was in one of my moods where "By golly, I'm not reading the stinking documentation, I'm figuring this out myself."  Well after an hour or so of this, I finally discovered, SubSonic really likes primary keys on the tables it's generating code for.    I had a few tables that didn't have primary keys (I know, smack me now), anyway's I throw those keys on and all is well. 

I'm really liking SubSonic and I tend to agree with Rob more than Jeff in the recent debate (makes for a good read).

Saturday, November 03, 2007 11:02:25 AM (Eastern Daylight Time, UTC-04:00) | Comments [0] | .NET#
Tuesday, October 30, 2007

I love the ClickOnce technology of smart clients.  What a great way to distribute software to my clients.  Since I'm an independent with many clients all in geographically different locations, most of which I've created a mixture of web apps and winforms software for, smart clients have simplified my job greatly.  Someone needs a quick fix or tweak, presto, from home, I make the change, publish it and there off and running.  No more taking an hour or so out of my day to go spend 5 minutes distributing an update on site. 

There are pitfalls to the clickonce technology however that I've discovered.  Mainly the issue of the expiring certificate which requires and uninstall and reinstall of the application.  A buddy of mine has created a workaround that using the C++ code in the KB article linked, that fixes the issue, but still not an optimal solution.  Supposedly this is fixed/changed in Orcas.  I'll have to dig up his solution and blog about it soon.

Wondering though, is ClickOnce used in the wild much?  For standalone apps, commericial or otherwise?  I would think that there would be some, but having difficulty finding any.  Just curious if the ClickOnce model is viable for a released product.

Tuesday, October 30, 2007 3:54:10 PM (Eastern Daylight Time, UTC-04:00) | Comments [0] | .NET#
Monday, March 12, 2007

Here's something handy to know that I had a bit of trouble finding information on. Perhaps I didn't look very well, but I was working with a colleague who had created a ClickOnce app and was having an issue where it appeared some of the files weren't being updated properly when he published a new version. Well, the problem turned out to be something else, but we were still curious on where the actual files were being downloaded to. After some digging, we found them at

C:\Documents and Settings\Jason Lautzenheiser\Local Settings\Apps\2.0

Under that folder are two more folders one called DATA and the other with what appears to be a random name. Under randomly named one, two levels deep are the main folders where all the different smart clients are downloaded to. It appears that each smart client will keep two versions, the current one and the previous version. I'm assuming this is for easy rollback a version.

Under the DATA directory any application files that the Publish Status is set to DATA.

Maybe this is well known, but it doesn't appear to be well documented.

Monday, March 12, 2007 11:15:53 PM (Eastern Daylight Time, UTC-04:00) | Comments [0] | .NET#
Wednesday, February 21, 2007

Been a while since my last post and February has been slow in general as far as the blog is concerned….just too much work to do. I'm trying to finish up a very large project and running into a few snags here and there which are taking that extra time and just putting in the extra hours to get it done. Here are a few links that I need to go back to once I get a free moment or two.

  • Reflector 5.0 – This is a no brainer….just go out and download this. I grabbed it the day it was released and as always a great tool with some nice new additions. Scott has a nice write-up on some new features so I won't repeat that here, just go get it.
  • ViewState Helper – This looks like a promising tool to check out. Haven't played with it as yet, but reading up on it, it looks very useful.
  • I'm no CSS guru so I definitely have not used these…but here is a list of CSS Properties you Probably Never Use.
  • I've been on a Pattern kick lately. Here are a few articles I need to read sooner than later.
  • One thing in regards to patterns….I've got to watch, because as I read and learn more, I tend to look at my current project and see where I can fit this pattern in there and that one in over here. That is not always the most productive path to go down as you're meeting deadlines. I've got to focus on finishing the project (which the architecture is already set) and come back to some of these things as we do revisions in the future. I have a fairly large project which design will start on in another month or so which I can look forward to implementing some patterns in the design of that project if they fit.

Be on the lookout for a new post or two on things I've learned from a previously employer. Some topics coming up are taking a look at my first day on the job (or how not to treat your new employee), how we were tasked with the impossible task of translating a huge system originally in DOS to a windows application in 3 months with ever changing requirements yet a firm due date, and how to kill a giant (otherwise known as reinventing the wheel).

Wednesday, February 21, 2007 11:16:10 PM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET | Midnight Snack#
Tuesday, January 30, 2007

We have a house full of sick kids. All have pretty bad chest colds. It really hasn't been that pleasant around here, though I'm hoping that I may escape from getting it.

  • I just heard that author Sidney Sheldon died today at age 89. I can't say that I was a huge fan, in fact I don't think I've ever read anything of his, though I know some who just love his work. I can however respect anyone who has the muse within. I have been trying to get myself to sit down and write. While I work in a technical field, I have no desire to write technical books (in fact I read very few technical books these days). I have too many stories inside that I need to get out someday. A friend of mine, who is an aspiring author, once told me that the only way to become a good writer is to just sit down and do it.
  • On that note, however, I read an article today that states called, How to Become a Better Programmer by Not Programming. Interesting premise and to a certain degree I agree with Jeff on that. It is true that there is a vast divide between those that are excellent programmers and those that just get by. I think that I can tell in a very short time whether someone is an excellent programmer or not. Unfortunately those mediocre programmers often see themselves as top-notch and on the flip side the really excellent programmers are normally fairly humble about it.
  • Ahhh yes….. tax season is upon us. I've just finished up preparing the last of my 1099s I need to prepare for some sub-contractors I had work for me this past year. Nothing like waiting until the last moment. I've only received one of the one's I'm expecting as of yet, but should see the rest of them here in the next week or so.
  • I think I'm going to start a series of posts relating some interesting stories (funny, scary, sad …) from a previous employer. The names will be changed to protect the innocent, though if you know me; it won't be hard to figure out who I'm talking about. No offense meant to anyone, but hey, they are my life stories and I'm going to tell! I learned a lot from working there some good, some not so good. So anyway, be prepared for some.
  • Just for a taste of what I'm talking about, here is a list of some SQL don'ts. This list that Brian put together mirrors some things that my former employer did, despite advice against.
Tuesday, January 30, 2007 10:54:50 PM (Eastern Standard Time, UTC-05:00) | Comments [1] | .NET | Midnight Snack#
Monday, January 29, 2007

Well here's one that has me stumped. Basically what I have is a ClickOnce deployed app that is deployed to my client's network. I would like to pass it some command line parameters, but for the life of me cannot get it to work. All the examples I can find are for web-deployed click once apps, but the code given there does not work. For web-deployed apps it's very easy to retrieve the parameters using,

AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0].Query

and parsing out the parameters (normal query string parameters like www.blah.com/myapp.application?param1&param2). However when using the same construct with the network-deployed app, this simply returns the name of the application file (file://myserver/apps/myapp.application?param1&param2 simply returns apps/myapp.application). Trying to pass parameters in any other way results in windows not finding the application file.

Either I'm overlooking something very obvious or there is just no easy way to do this. Luckily this isn't a must have feature for this particular client, just something that would be nice.

Any thoughts or ideas?

Monday, January 29, 2007 9:55:11 AM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Thursday, January 25, 2007

This one had me stumped. A large web app I'm working on for a client has some cases where some AJAX would be very handy. I wanted to take this opportunity to learn about ASP.NETs AJAX release as it looked real easy to work with. I watched the videos and followed the instructions and created a test app and all worked well. I then tried to take what I had learned and incorporate it into my existing app. The Partial Rendering did now work and the SupportsPartialRendering continually came back as false. I had checked to make sure that all references were in place and the web.config file was updated with the required <httpHandlers>. Well interestingly enough, I missed a very important part of the web.config.

<configuration>

    
<system.web>
        
<xhtmlConformance mode="Legacy" />
    </
system.web>

</configuration>

With the xhtmlConformance mode set to Legacy, AJAX will not work on your pages. Scott Guthrie has a good explanation with all the gory details. In a nutshell, apps that were upgraded from 2003 to 2005 (which mine was) will have this setting in place. Removing that and automagically, my newly AJAXed pages now work as designed!!

Thursday, January 25, 2007 10:17:27 PM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Friday, January 19, 2007

Well in concordance with this, I've decided to post about my favorite tool.  Well in coming up with my favorite tool, I had to search through many of them that I use and love.  But most recently, I believe my favorite tool, that I use every single day has to be ReSharper from JetBrains.  This add in to Visual Studio (I use Resharper 2.5 for VS2005) adds so many tiny benefits it would be hard to list them all.  Just go their site and look through the feature list.  It's simple, fast (as of the new version, the past versions did have some speed issues) and it stays out of the way.  I've gotten to the point now where I don't even realize it is there.  I was at a coworker's machine, which does not have Resharper installed, and I was amazed that I was able to get anything done without it.

Hard to say what my favorite feature is, I really like the Usages (Alt-F7).  The Ctrl-Click Go to Definition is a huge time saver.  Surround With (Ctrl-Alt-J) is another tool I use alot.  I could go on and on.  The hardest part for me has been learning some new keystrokes, for some of the lesser used items, the keystrokes still escape me from time to time, but I'm getting better. 

I won't get into a ReSharper vs Refactor Pro holy war, as both products have a ton of nice features.  I wish I could take the best of both, combine then into one and you would have one killer app.

Oh BTW, JetBrains has just put out an update as I've mentioned previously

Friday, January 19, 2007 10:43:15 AM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET | Cool Tools#
Wednesday, January 17, 2007

I guess I've been under a rock, because I just discovered this operator this evening.  Catching up on some of my unread blogs and read this post on Tests for Null in which mentioned the new coalescing operator (??) in C# 2.0.  How had I never noticed this before.  I could use this almost every day and I'm always one for neatness and compact code so this kind of operator will fit nicely into my toolset.

How does it work?  Well it simply checks if something is null, if not null, returns that something otherwise if null it returns the alternative.  Works very similar to the Coalesce keyword in SQL Server (which I do use often)

ThisClass objClass = aClass ?? new ThisClass();

Which is equivalent to

ThisClass objClass;
if (aClass != null)
   objClass = aClass;
else
   objClass = new ThisClass();

and also;

ThisClass objClass = (aClass != null) ? aClass : new ThisClass();

 

Wednesday, January 17, 2007 10:32:22 PM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Thursday, January 04, 2007

This is something that I tend to forget even though it's pretty basic and probably obvious to most.  I have a comma delimited string which I wanted to put into a List<>.  Here's a one-liner to get the job done.

   List<string> aList = new List<string>();
  aList.AddRange(myString.Split(','));

Where myString is my comma-delimited string.  Pretty basic, but very handy.

Thursday, January 04, 2007 10:06:53 AM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Monday, March 20, 2006

Not sure how I missed....but here is a very handy new feature in VS2005.  Thanks to Jessica for pointing me to this.  Had I not stumbled upon this I would still be tracepoint-less. 

What is a tracepoint?  Well, in a nutshell.  It's like a breakpoint without the breaking part.  I can now use this to replace some of my Debug.WriteLine statements I use to debug in certain cases.  How to create a tracepoint:

  1. Create a breakpoint as normal.
  2. Right-click on the red circle indicating the breakpoint.
  3. On the context menu, select When Hit.  There are other options as well, though they deal with breakpoint filters and such that I believe were in previous version of VS.
  4. Fill in the dialog with whatever text you wish to print, you can even run a macro.
  5. Close dialog, and red circle changes to red diamond indicating a tracepoint.

Very handy new tool and another reason I like VS2005 more and more each day.

Monday, March 20, 2006 10:37:05 AM (Eastern Daylight Time, UTC-04:00) | Comments [0] | .NET#
Tuesday, March 14, 2006

Well, everyone else seems to be doing it.....  I come across quite a few links each day that interest me or I should investigate further.  Here is my attempt to list those ...  while I would like to say daily, I really doubt that will happen.  Here is my first short batch.

  1. Reading Excel with ADO.NET - an interesting look into how ADO.NET handles Excel Docs.  Most interesting was how it guesses the data type of each column.
  2. Creating a unique or semi-unique ID in .NET  - As I ran into a similar situation not too long ago (I actually stuck with using GUIDs as in this particular application, the length didn’t matter to me), this opens up a discussion on the GetHashCode() method used on a GUID to create a semi-unique ID.
  3. Using ResolveClientUrl in markup This comes in handy more than not, but it is invariably something I forget about each time.
Tuesday, March 14, 2006 7:57:05 AM (Eastern Daylight Time, UTC-04:00) | Comments [0] | .NET#
Wednesday, February 22, 2006

I ran in to a bug today in regards to a ClickOnce app I've developed for a client.  I inherited a website that was partially completed when I has hired on by my client.  I developed a ClickOnce app for them (actually two different apps) along with completing and enhancing the website.  Portions of the website run with an SSL Certificate (through HTTPS), the certificate was purchased long before I came into the picture. 

The ClickOnce client app is launched from within a secured area of the website.  Everything worked fine, until someone browsed in through a different sub-domain.  Specifically the Certificate is for www.blahblahblah.com where as the client where we received an error came in through http://blahblahblah.com (without the www).  The certificate is not a wildcard certificate so if I had browsed to that page I would have recieved a Security Alert message box with the message:

The name on the security certificate is invalid or does not match the name of the site.

Well while browsing it's simple enough to click yes to proceed, however you don't get that option and are simply presented with the Cannot Start Application dialog.

Clicking on Details gives a ton of information on the exception that occurred.  Looking down I see the following:

--- Inner Exception ---
  System.Security.Authentication.AuthenticationException
  - The remote certificate is invalid according to the validation procedure.

So I can see that this is related to the Security Alert given above.  After doing some digging, it appears that this is an acknowledged bug with .NET 2.0.  While this isn't quite the same scenario that I ran into, it looks to be similar enough to possibly be the same cause.

I'm not that versed on SSL and security issues in 2.0, so my speculation may be incorrect.  The client was happy enough to be sure to include the www and I can always redirect so it wasn't that big of an issue, but thought it was interesting enough to share.

Wednesday, February 22, 2006 6:29:16 PM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Wednesday, February 15, 2006

Just discovered this today (yes I'm a bit behind, version 1.0 was release July 25, 2005..)....I had some legacy INI files that needed parsing and I've got a general class that I use normally in cases like this that handles all my INI needs.  Generally it works fine as it simply wraps the API.  I found recently that with .NET 2.0 (at least that's all I've tried with) there is a issue with reading an INI that resides on a networked drive.  Needless to say, I needed to do just that.  After a brief look I came across NINI, a nice tool that not only handles INI, but also XML configuration files, Registry,  .NET configuration files, and command line parameters.  The INI functionality at least was written without the use of API, so it runs just fine reading the INI across the network.  I haven't looked any deeper into the other files it can handle, but I've got a few uses for this library already.  Wish I would have discovered this one long ago.

http://nini.sourceforge.net/

Wednesday, February 15, 2006 5:33:22 PM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET | Cool Tools#
Thursday, January 19, 2006

I switch daily between c# and vb.net for different projects with different clients.  One of the things I've always plagued me was those subtle little differences between the languages; putting semi-colons at the end of vb.net code, typing Then....EndIf in c#, those types of things.  Those are easily noticed as soon as they fly off my keyboard.  The ones that are really evil are differences in techniques that, at least I, just don't use that often.

For example, yesterday I was working on a vb.net project for a client.  I created a new class that I wanted to implement an interface.  Not a big deal, I remembered that in VB you need to use the Implements keyword.  What I didn't recall, and embarrassingly enough took me a few minutes to discover what I was doing wrong, was that you needed to use the Implements keyword tagged on the end of each method in the interface.  It's something I don't do quite enough to have it instantly recalled when I need to (although perhaps by writing this up, I will forever have it etched in my brain, "What's wrong here, why isn't it seeing the methods I implemented....Oh yes, remember that blog entry you wrote last year....need the Implements on the methods!!!"   Another benefit to blogging!

Thursday, January 19, 2006 7:37:18 AM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Friday, January 13, 2006

Two days ago my host (a fairly well known host that I recommend to almost all my clients) changed the trust level on all their shared .NET 2.0 servers at the recommendation of Microsoft.  Unfortunately, little warning was given and some sites broke because they were depending on Full Trust.  I had two of those myself, not really sure what was causing  the need for full trust. 

After investigation, it appears that third party web control I was using on these sites require full trust and was causing my problems.  Now that I figured that out, I contacted those third-party companies and unfortunately those controls do not work in partial trust, although one company at least put the request on the feature request list for a future version.  Not much comfort for me at the moment however. 

Fortunately, the dependence on these controls is minimal and in my case will take some minor work to work around.  However, I know of some other sites that will not be as lucky.  I can understand the security reasoning behind running in partial trust, but it is very hard to explain to a client why there site which worked fine in the morning, suddenly no longer works in the evening, seemingly for no better reason than the site host upgraded the security.  Security of your site matters little if it is down.  So needless to say, I have some work ahead of me to change the sites to work under partial trust.  I also imagine we will see quite a few updates to 3rd party controls to run under partial trust if that is what Microsoft is recommending to hosts now.

One good thing that came from this, it put me in a position that I had to learn more about the different trust levels and what I can and can't do in each....something I perhaps took for granted in the past.

Friday, January 13, 2006 12:46:12 PM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Monday, January 09, 2006

Older post on setting focus to a control in ASP.NET, but found this useful today.  Something I do often enough that I don't want to have go searching again for it.

Monday, January 09, 2006 10:03:26 PM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Thursday, December 29, 2005

Well as I alluded to in a few previous posts, I was running into issues with my 1.1 No-Touch Deployment smart clients I developed for a client of mine that ran across the internet.  Well I've finally found something official from Microsoft in regards to this issue.

Bug Details: .NET Framework 2.0 breaks No-Touch Depoyment (HREF exe) apps from the Internet

There are a few workaround's posted which you may get varying mileage out of.  I in fact took the third suggestion when I converted them to 2.0.  This actually worked out pretty well and from the looks of things, this was really the only good solution that worked in our situation.

This should be considered pretty critical as it breaks existing code which can cause great problems.  In our case, it was easy enough to convert them to ClickOnce apps which enabled us to take advantage of some other enhancements, but for others this may not be so simple or feasible.  Non of the other solutions look appealing either at least for our application. 

Thursday, December 29, 2005 9:01:45 AM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Thursday, December 22, 2005

I was trying out the VS 2005 Web Deployment Projects addin on one of my websites.  Wanted to merge all to one named DLL.  I was getting an error "Aspnet_merge Exited with Code 1" with very little other detail.  After some digging found the solution (at least in my case).  It appears that I had a duplicate class name in my project (actually had two of them).  Once those were cleaned up, build succeeded without problems.

 

Thursday, December 22, 2005 11:26:11 AM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Saturday, December 17, 2005

Here's a nice list of the new and improved security feature in the 2.0 framework.

New and Improved Security Features in the .NET 2.0 Framework

Good reference.  I need to go through this and learn what I can, I'm sure I'll have some comments as I read through this and play with some new things.

Saturday, December 17, 2005 10:05:27 AM (Eastern Standard Time, UTC-05:00) | Comments [0] | .NET#
Search
Archive
Links
Categories
Admin Login
Sign In
Blogroll
Themes
Pick a theme: