CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

January 2007 - Posts

  • Tagged

    This viral tagging thing must be almost burned out since it finally got down to little old me.  5 things you don't know about me:

    • I would actually leave development and become a science and tech teacher if there was any money in it (there isn't).
    • I dyed my hair green in college, got a tattoo of a dragon on my shoulderblade, and was a skater punk type. (Of course now I look like your average nerd)
    • I can will myself to fall asleep anytime, anywhere, within 3-5 minutes.
    • I took 8 years of classical piano when I was young.  I recently acquired a piano for my home and plan to start playing again.
    • For extra money and exercise time I referee youth soccer.

     

  • Calling a Master Page User Control from a Page User Control

    Now if that title isn't a mouthful, I don't know what is.  Anyways, this is something mostly for my benefit because I conveniently forget about this little trick and then have to go rooting through my code to remember and I'd rather have Google index it for me.  =)

    So I have this nifty little status message user control in the master page of my current project. It basically leverages a repeater to show a list of status messages with icons next to them based upon the type/severity. The idea is to have a method in the master page that takes a message and type as an argument and adds the message to an internal list which binds before render when all the processing is complete.

    The problem is, I want to call to the user control from a user control in a page, so I have to jump two levels "up the chain" so to speak. Now, I hate FindControl() so I want it to be strongly typed to, so here is the solution I came up with.

    Create a base page for the master page

    Create a class, inherit it from master page, expose a virtual method which in my case writes a message. In this base page, I'm just dumping the message out in response.write since there's no user control here necessarily to handle it.  MessageType is just an Enum I created with types like Success, Warning, Error, etc.

    public class BaseMasterPage : MasterPage
    {
        public virtual void WriteMessage(string Message, MessageType Type)
        {
            Response.Write(Message);
        }
    }

    Inherit your master page with the control from the BaseMasterPage and override the virtual method

    The beauty of this is that I now have a common interface across my master pages for accepting messages from pages and user controls. They can all handle the messages in their own way.  In the case of the following master page, I get a strongly typed call to my status message control (as I said before, it binds in the PreRender since it will have collected all the messages by then):

    public partial class MyMasterPage : BaseMasterPage
    {

        protected void Page_PreRender(object sender, EventArgs e)
        {
            StatusViewer1.BindStatuses();
        }
       
        public override void WriteMessage(string Message, MessageType Type)
        {
            StatusViewer1.AddStatusItem(new StatusItem(Type, Message));
        }

    }

    Internally, the viewer just as a List<StatusItem> of which status item is just a barebones object for the strongly typed generic (I love those damn generics).

    In the case of a user control on a page, you just have to ensure that the master page being called is of type BaseMasterPage, and then pass the message out accordingly. Here's a snippet from one of my user controls:

    if (Page.Master is BaseMasterPage)
    {
         ((BaseMasterPage)Page.Master).WriteMessage("Some warning message.", MessageType.WARNING);
    }
    else
         throw new Exception("You're supposed to inherit from BaseMasterPage, Doofus.");

    Anyways, the point is that inheriting from your own custom base classes lends you a lot of extra firepower when it comes to dealing with pages and master pages and .net 2.0.  Creating a BaseMasterPage and BasePage are two of the first things I do in about any project.

     

  • Predictions for 2007

    Some humerous, some serious.  Here we go!

    YouTube goes down in history as one of worst business decisions ever

    After the **AA machines chew it up and spit it out, YouTube goes the way of the napster and other content providers before it. It will also then hold the record as one of the most expensive acquisitions ever. 

    Vista is released, Slashdot kiddies claim "Year of the Penguin" regardless

    Up until, and shortly after the release of Vista, at minimum there will be 10 "articles" a week claiming that Vista is flawed, Linux is better, and that Microsoft is the Sux0r. In the first year or so they will also continuously site articles of a low Vista install rate conveniently ignoring that operating systems really don't hit their stride for 3 years or so. The real world will ignore this, buy Vista anyways, realize that just about everything published on both sides is hyped up bullcrap, and enjoy their new OS with Solitaire in 3D.

    The Expressions Product Line will bridge the gap between developer and designer

    I actually accomplished something I never thought would be possible this last year.  I weaned our designer off of dreamweaver and got him to do all his work in visual studio using app_themes and other nice ASP .NET 2.0 features. If the Expressions product line accomplishes half of what it promises, it will be a serious problem for Macromedia.

    The console war will be about even

    I'm predicting the Wii, PS3, and X360 to just about tie in North America.  In Japan, the Wii will probably dominate if it can keep releasing innovative titles and get those 3rd party vendors cracking away.

    Democrats will be just as corrupt, useless, and stupid as outgoing republicans

    Every time I pull a voting lever, I feel like I'm just voting for the lesser of two evils. I'm starting to take the position that I don't care who is in power, just so long as I get to keep more of my own money since neither party has done jack for me in decades.  Nuff said.

    Windows Presentation Foundation will likely flop

    Sorry guys, I've seen it, I think it's cool as hell, but I just don't see anyone having the time/effort/motivation to switch away from ASP.NET to WPF. Besides, with the booming Web 2.0 propaganda, I think that many executive type folks won't buy into WPF in the near to mid term.  It's a shame though... I like the technology.

    Web 2.0 will be mostly hype, and then the next tech bubble will burst

    I don't see the fallout being nearly as bad as 2000-2001, but we still have a bunch of web/software companies getting a lot of funding with weak profit models and no real assets. Say it with me kids, if all you have is some glitzy software, you're only safe until some geeks in their garage create a better knockoff of it. A winning company needs real assets, advantages in core processes and the ability to provide a unique service that is hard to duplicate. GMail, YouTube, Flicker, etc etc etc will never be primary drivers of profit.

    The USA will continue to lag in the broadband race

    Certainly we have a disadvantage in that our population isn't as condensed as top performers like South Korea, but our government and regulators like the FCC have no freaking clue how to manage and infrastructure and encourage upgrades. The fact that one congressperson on the comittee can't even describe the internet and we actually see the need for a net neutrality act bodes very ill for the internet in general. It's a damn shame too because for as much hype as government likes to put on job growth, education, and new opportunities in tech they sure don't want to put a dime into an open infrastructure to support it...

    Ruralsourcing will begin to eat away at offshoring

    You know, there's plenty of talented american tech workers to be had at bargain prices in the south and midwest. Companies disenchanted with the difficulties of managing global projects will start to turn their eyes back to the USA and realize that even paying a US wage premium once you factor out all the other communication barriers, management barriers, and difficulties of managing foreign law and regulations  it's about a wash, and your US customers are so happy to get a native english speaker on the phone when they call you.

More Posts