Master Pages in .NET 1.1

by Damon 26. January 2005 06:00


In the place I am consuling right now, the Enterprise Architecture team has created a library that mimics the ASP.NET 2.0 Master Pages functionality. VS.NET 2005 is not production ready yet, and like many other large shops they typically do not use something before it has had at least one service pack. Sound thinking; being on the bleeding edge is fun but hard to justify the risks for big business.

Still, this is very useful stuff. Lacking the source code to this library, I sat down myself to try to duplicate this. The implementation used at work is an HttpModule, but I remembered using Page.LoadControl() to solve a problem recently, and I wondered if it might be just that simple...

                   private void Page_Load(object sender, System.EventArgs e)

                   {

                             string controlToLoad = Request["c"];

                             if (null != controlToLoad)

                             {

                                      Control c = Page.LoadControl("controls/" + controlToLoad);

                                      myControl.Controls.Add( c );

                             }

                             else

                             {

                                      Label l = new Label();

                                      l.Text = "No control to load";

                                      myControl.Controls.Add(l);

                             }

                   }

So, with the name of the content control as part of the URL, I started experimenting.

Twelve lines of code, and it seemingly works. I have an ASPX page which I call Master.aspx. On this page, I have whatever heard/footer common info, and in the place where content sould vary an <asp:PlaceHolder Runat="server" EnableViewState="True"/> So far, it seems to work, although I've only briefly tested it. Is this too easy? Does anyone know of any issues with this method?

Tags:

IT Slavery

by Damon 25. January 2005 06:00

Something has been bothering me, something that I need to get off my chest.

Since I put up this blog, I've had several people contact me because they found my resume via a search engine. In talks with these folks, they of course ask me what I'm looking for in a job, and why I might leave my current position, etc. Many times, I have had a phone or personal conversation that goes something like the following:

Me: One thing that is important to me is freedom, ability to do side work for extra money and own any code that I write at home.
Them: Well, we have to protect our business...
Me: I understand that, and of course I could not do anything that was competing with you, but rather smaller projects off hours for people who can't afford a consulting company.
Them: Well, we're looking for someone to help grow our business. We need someone who can help with sales calls and write proposls, and your skills are clearly what we are looking for. If you have extra time we would expect you to spend that time helping us with sales, and writing proposals, and preparing demo programs.
Me: I see, so, I assume side work like this would not be allowed at your firm?
Them: Correct. We expect you to be too busy to do side work anyway.
Me: Ok. So, I assume I would be compensated for the time I spend doing these things, since you have identified these activities as vital to your business.
Them: Well, no. Only billable work is payable. Sales work is not billable. Our people are salaried and no compensation is available for sales work.
Me: (In a last ditch effort to make some sense of where this person is coming from) Oh, I see, so you must offer some small sales commission or annuity based income if the sales effort is successful then?
Them: (Answering in a tone that I might expect if I'd offered to sell them Crack Cocaine while speaking Russian) No ...
Me: I'm not sure this is a good fit.

Someone called me again today, and I had this conversation with them. Before I make my point, let me reiterate:

  • Doing work outside the company is forbidden
  • I am expected to work overtime constantly, as part of my job
  • No addtional compensation is available, even though the work is of vast benenfit to the company

Are we becoming a nation of white-collar slaves? Are we so averse to risk we'll let somone own every hour of our lives as long as they promise a regular paycheck? Don't get me wrong, I understand that from time to time at any company there will be a need to put in more time. When something big hits, its "All hands on deck", and you hope your efforts are remembered later. But, this all to common conversation is insane. You will require me to work overtime, so much so that I can't even go work at Blockbuster for free movies if that's what I wanted to do. You won't pay me for overtime, and on top of that you won't even throw me a bone if my efforts bring great success to the company.

Why anyone would knowingly enter into this is beyond me. If you have technical skills as well as the ability to not make an fool of your company in a sales meeting, you're probably not going to have too much time finding employment. Furthermore, if you are actually successful in being a sales person and delivering work, why would you want to do so for free so that someone else can reap the benefits of your skills and your hard work? On top of that, if I turn out to be no good at this task, you'll likely fire me and replace me with someone who is good at that task. If I turn out to be good at the dual life of delivering good work and doing sales, I might start to think I should be working for myself, or having other people work for me.

Can someone please explain this to me?

Now, I am not advocating getting paid if you happen to think about work at home, and as I already said, I think employers asking a little extra during a crunch is perfectly acceptable. However, asking someone for their talents, and giving them an up front guarantee that you will in no way pay them for their time nor will you let them supplement their income is ridiculous. Saying that you'll "take care" of someone, implying that they might get a slightly bigger raise next year if they work 500 hours of overtime, is also completely ridiculous. We all know that the time we could trust Corporate America to be fair ended long before we had horrible examples like Enron to show us that "We'll take care of you" is a crock. If you intended to pay me for my time, pay me for my time.  If you try to paint a scenario in which you want me to think you are going to pay me for my time but the only vehicle for this is a yearly review, I'm going to be very suspicious of your intentions of goodwill and fairness. 

I'm not advocating a strict "What's in it for me?" policy either, although you are the only person looking out for you, usually. I am happy to say that I have also talked to two or three business owners lately who sing a much different tune. These conversations include things like:

  • If you bring us a sale because of your relationships, reputation, or time spent, we'll cut you in
  • If we ask you to work off hours on sales work, we'll throw you a bone for your time if the sale does not pan out
  • We won't pay you hourly for your time on sales work, but if you do help us get sales we will give you a small %
  • Share the work, share the reward
Fair is fair. Something for something. Why do so many employers in IT offer Nothing for Everything?

Am I being unreasonable and selfish here? I don't think so, but comments are always welcome.

Tags:

FileSystemWatcher on the Compact Framework

by Damon 20. January 2005 06:00
In order to keep people well fed here, I'm thinking I'll try to post something interesting once a week or so. I've got enough things in my vault to fill in the gaps if I don't have time to write something new...

Today I'll share another small .Net Compact Framework item. You may be familiar with OpenNet CF, which fills in the gaps for many of the familiar things missing in the compact framework. However, some of these gems rely on the existence of "aygshell.dll" as part of the OS image. This may leave you without a Managed solution and without the ability to PInvoke your way to your goal.

One such handy tool is FileSystemWatcher. Supposing you need to write code to fire an event when a file is created in a certain directory.

There are a few things you'd want to think about:

  • Thread safety.
  • Ability to work with a UI thread safely
  • Ability to detect if a large file is completely done, as opposed to just in the process of being created.

One approach might be to create a class, call it something original like FileSystemWatcher. This class can have Start() and Stop() methods. Internally, it will create a thread that runs at a specified interval and does a directory search based on a given path and given search pattern. (Maybe *.jpg) Since there is no Thread.Abort() on the compact framework the class will need to put mutexes in the right places so that it can be killed by having a _stop bit somewhere.

With that out of the way, you can detect changes. By using Control.Invoke and an EventHandler, you can safely notify UI controls that the file they are looking for has been found. What about knowing when a file is complete? This part could be OS specific. On CE.NET, the filesystem creates a 4096 byte file pointer on the filesystem as soon as a new file is created. Detecting unchanging file sizes greater than 4096 bytes with FileInfo will then tell you that a file is complete. If your program needs to respond to files being written to a filesystem by webservice, network share, FTP, or Http download, you can delay processing untill the file is done. Not pretty, but if your OS image is missing some things, what can you do but improvise (Or write native )? Maybe I should write a cleaner C++ version which could then be PInvoked? Maybe if I find myself with a great deal of spare time on my hands!

By adding some code, the file change and file delete events could be detected as well. I won't post the code for this particular item here but I can help anyone who needs this functionality in the CF.

Tags:

New Job

by Damon 19. January 2005 06:00
Well, I suppose it is now official. I have resigned my position at Centare Group and accepted another position.

My time at Centare was pretty good. It was there that I eventually started to grow into the leadership/senior roles I've always wanted. It was during my time there that my daughter was born, and a lot of other huge life events happened. It was at Centare that I wore the title "Microsoft Business Group Manager" for a while and did a great deal of work with Brian Tinkler trying to get Centare up and running and known as a solid Microsoft partner. (After many years of good rep as a solid IBM partner) Either because of, or inspite of, those early efforts Centare went from zero to several .NET people.

My new gig will be Principal Architect at SafeNet Consulting Services. They are also looking to grow their Microsoft practice and the opportunity seems like the right thing at the right time.
Not only will I get a fancy title on my business cards, but SafeNet's model will offer me a little more freedom where my own business endeavors are concerned. Hopefully, this opportunity combined with some big personal events (like building a house) will make this a fantastic year for me and my family.

One of the biggest take aways from my leadership reading this year is the notion of the Abundance Mentality. In keeping to this principle, I wish Centare all the success in the world, and look forward to chasing after my own.

Tags:

Compact framework

by Damon 15. January 2005 06:00
While surfing the dotnet public newsgroups for solutions to other issues, I came across two questions over and over again related to the Compact Framework. Perhaps if I post solutions here Google will help people find the answer in plain English and C#.
  1. How can I be sure to run only 1 instance of my application on the compact framework?
  2. Dotfuscator Community Edition doesn't work on the compact framework!

Like most things that are missing from the CF, the easiest solution to #1 involves using PInvoke to access functionality in the Win32API:

                   [DllImport("coredll.dll")]

                   private static extern int  FindWindow(string lpClassName, string lpWindowName);

 

                   [DllImport("coredll.dll")]

                   private static extern bool SetForegroundWindow(int hwnd);

            int hWnd = FindWindow( null,  "Main Window title");    // you can also add your app class name

            if (hWnd != 0)    

            {     // bring to the front the other instance

                SetForegroundWindow(hWnd);

                                      return;

            } // else run new instance

As I said, I also saw tons of posts related to Dotfuscator not running with Compact Framework Assemblies even though the vendor swears it does. The solution I found is twofold. The problem with the version distributed with Visual Studio 2003 usually manifests itself with something like "Unable to load some of the types"

  1. Register your copy of Dotfuscator and download the update for the community edition from their site.
  2. Even with some things in the GAC or plainly referenced by hard paths in your solution, Dotfuscator had trouble finding some of my assemblies. Changing some of my references (such as the System.Data.SqlServerCe reference) to "copylocal" allowed dotfuscator to run successfully on a very large compact framework application.

Happy coding.

Tags:

User Group Presentation

by Damon 12. January 2005 06:00
I did my cryptography presentation at the Wisconsin .NET user's group last night. It seems to have went well. Many thanks to WINETA for having me, and for the kind words and excellent questions from those who attended.
If they let me come back, Designer Support is the next topic I'd like to tackle. Designer support is probably one of the coolest features in .NET that is seldom used or talked about and yet is very powerful if you take the time to do it.

With the UG presentation out of the way, I can return to pondering some of my other tasks, such as the ASP.NET issue I posted before.

Tags:

About the author

Damon Payne is a Microsoft MVP specializing in Smart Client solution architecture. 

INETA Community Speakers Program

Month List

Page List

flickr photostream