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

Stephen Wright

My blog about ASP.NET programming in an enterprise environment and the challenges faced by programmers, project managers and clients.
  • Creating a Yellow Fade with ASP.NET AJAX Toolkit

    I've always thought that the Yellow Fade Technique has been a great way to present changes to a web page.  It's used in all of 37Signal's applications such as BaseCamp and CampFire.  It highlights the changes in a page using a yellow background, then fades out to the normal background.  This gives a visual cue to the user that something has changed on the page.  You can also use it to get the user's attention (which is what I use it for).

    I searched to find the JavaScript to use in my own application and couldn't find anything that was easily integrated into the "controls" structure of ASP.NET.  Anything that I was going to use would need to hack into the body tag and the header tag to place functions initializing it.  Here's a quick way to accomplish this using ASP.NET Ajax and the Control Toolkit.

    This example assumes that you have .NET 3.5 and the AJAX Control Toolkit installed.  If you don't have it, you can download the the .NET 3.5 Framework and the Control Toolkit from the official website: http://asp.net/ajax/

    For this example, I am using the AnimationExtender.  Here's the .aspx:

    <ajaxToolkit:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="divResponse" Enabled="True"/>
    <div id="divResponse" runat="server" style="width: 500px; padding: 10px;    margin-bottom: 10px;" visible="false">
        <strong>
            <asp:Literal ID="litResponseText" runat="Server" />
        </strong>    
    </div>
    Display Name: <asp:Textbox id="txtDisplay" runat="server"/>
    <asp:LinkButton id="btnSubmit" runat="server" Text="Update"/>


     

    The div named "divResponse" is the container for our response on postback.  We can now add the code to handle adding the Animation properties to the AnimationExtender:

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
            divResponse.Visible = True
            If String.IsNullOrEmpty(txtDisplayName.Text) Then
                litResponseText.Text = "Please enter a Display Name"
                AnimationExtender1.Animations = "<OnLoad><Sequence><Parallel Duration=""5""><Color Duration=""5"" StartValue=""#FF4500"" EndValue=""#FFFFFF"" Property=""style"" PropertyKey=""backgroundColor"" /><Color Duration=""4"" StartValue=""#000000"" EndValue=""#FF0000"" Property=""style"" PropertyKey=""color"" /></Parallel></Sequence></OnLoad>"
            Else
                'Save your Display Name property
                litResponseText.Text = "Updated Successfully"
                AnimationExtender1.Animations = "<OnLoad><Sequence><Parallel Duration=""5""><Color Duration=""5"" StartValue=""#FFD700"" EndValue=""#FFFFFF"" Property=""style"" PropertyKey=""backgroundColor"" /><Color Duration=""4"" StartValue=""#000000"" EndValue=""#008000"" Property=""style"" PropertyKey=""color"" /></Parallel></Sequence></OnLoad>"
            End If
        End Sub

     
    The first thing we want to do is to make the divResponse visible.  We then can start our processing.  We want to add properties to the AnimationExtender based on if the properties were set properly.  If it failed, we add the error text to the litResponseText Literal, then add Animation Property Tag, which would look like this in the end:

    <ajaxToolkit:AnimationExtender ID="AnimationExtender1" runat="server" 
            TargetControlID="divResponse" Enabled="True">
        <Animations>
            <OnLoad>
                <Sequence>
                    <Parallel Duration="5">
                        <Color Duration="5" StartValue="#FF4500" EndValue="#FFFFFF" 
                            Property="style" PropertyKey="backgroundColor=" />
                        <Color Duration="4" StartValue="#000000" EndValue="#FF0000" 
                            Property="style" PropertyKey="color" />
                    </Parallel>
                </Sequence>
            </OnLoad>
        </Animations>
    </ajaxToolkit:AnimationExtender>

     

    The Parallel tag will execute both of the properties at the same time.  What we're doing is starting the div with a background of Red/Orange and fading this color to white, while the text color is fading from Black to Red.

    If the Display Name was valid, we want to note a successful call.  This will fade the background from yellow to white and the forecolor from black to green.

    HTH

  • The Programmer's Dilemma

    I've been trying to come up with excuses why I can't come up with "examples" or "code improvements" for the ASP.NET community or more importantly: "What do I bring to the table?"

    I've been watching a lot of the conversations on the ALT.NET/CLI group and it actually makes me feel worse as a programmer.  We're a "young" group and people are trying to tell each other to do our jobs.  What really is the best way to approach coding?  What makes you a good programmer? (I posed this question earlier on Twitter).

    I've tried to think of real world examples of code that I've used that has been a "fore-runner" in the community, but I've run into a roadblock every time.  I write new code every day, but it seems so old and archaic to me.  Is that silly?

    Most of the code that I write involves the controls that I use in my application, and nothing to do with the code to retrieve data or work in the DAL.

    What does this have to do with current events in the .NET community?  Pretty much EVERYTHING!

    If you haven't been following, there have been multiple conversations on Yahoo's message boards about HOW you program.  People have left message boards because of their stance. It amazes me that people's opinions about computer science can steer a career in a different direction.  Being on the outside, looking in, I see that it's mostly an attack on how someone's approach on a problem is being criticized, not the end result.

    Take Frans Bouma for example. he has "exposed"(and not in a bad way) his view on programming and how it should be approached in different forums and been shot down in the most heinous way.  He was only stating the real world examples on what he has worked on and the "ALT.NET" community took a crap on him. 

    I don't think he was treated fairly.  He gave his opinion, people shot it down, and now, because of his opinion, he's anti-"ALT.NET".  That was hardly his point.  He simply wanted to give a point of vie that didn't apply to the "ideal" situation.  I agree with his stance since not every every programming situation calls for TDD and interfaces and mocks.  I have been in plenty of different situations where I don't have time to build the interface, DAL, BLL and tests in time for it to ship to the customer. 

    In these situations, you have to feel comfortable that what you have built is what the customer wanted in the first place and not about how you feel how you programmed.

    Which brings me back to my original question on Twitter:  "What makes you a good programmer?"

  • Time Zone Issues

    Sounds like a book title, doesn't it?  It's a horror story. 

    Currently, I'm using a class library that uses the Windows Registry to return information about a specific date.  I found it on Code Project and it REQUIRED a full trust environment. Luckily, I didn't need to run in a shared hosting environment and I didn't want to build my own DST provider for every time zone.  I've been using it for about 2 years now and I think it's time to move over to the new TimeZone2 functionality that will be included in the .NET Framework 3.5 release.

    Kathy Kam, member of the BCL Team, says from a post a while ago:

    In the “Orcas” September CTP, you’ll see that the BCL team has added a new class named “System.TimeZone2” that will allow you to:

    • Convert a DateTime from one time zone (not necessarily your machine’s time zone) to another
    • Get an object that describes your local time zone
    • Get an array of objects that describes all the available time zones on your machine
    • Serialize a time zone into a string
    • Create your own time zone object to represent any custom time zones

    The best part about this is that… if you are on an Vista machine… all of those functionality will have Vista’s Dynamic Time Zone support, because our calculations are done with the time zone data available on your OS.

    This is wonderful news for me.  I no longer have to depend on the old class library to store my time zone information.

    For more information on the TimeZoneInfo Class, you can read about it on the MSDN site.

  • My Unit Testing Challenge

    Objects I've always thought of myself as a decent programmer.  I'm able to find solutions for people and I get rave reviews on how great something works.  However, there's always been a part of me that knows that I can program it better using agile methods and sound fundamentals.

    I haven't taken the time to implement unit testing in my application because of time constraints.  It's been one of those things that has always left a sour taste in my programming mouth.  For an application that spans 300 pages, 200 controls and 100 Controller Modules, you'd think that I'd have a better handle on the code and a testing plan in place.

    nunitInstead of automated testing, we have our QA team go through printed scripts (some over 200 pages).  Some of the site is still undocumented and we do not have a formal testing plan, so we have to remember to test it out before it's sent to the customer.  As a rule of thumb, we've always set aside double the time we estimate for programming.  Not the most efficient way to estimate, but it's worked for us in the past.  We've gotten to the point in a program that it is no longer practical.

    Why am I able to get away with this?  I am the architect.  I am involved from the kickoff to the deployment.  I am creative control.  I can tell you in 30 seconds whether or not a certain feature exists.  If something doesn't work properly, I'm the one to fix it.

    The solution to this is putting in unit tests for all of the code in the site.

    Jeremy Miller from CodeBetter is a proponent of Unit Testing and Agile methods.  He says in his Programming Manifesto:

    "An axiom of software development is that problems are cheaper to fix the sooner that the problems are detected.  If you take that axiom at face value, it's easy to see why I put far more weight into comprehensive test-first unit testing because it gives you far more rapid feedback to find problems fast.  Small, isolated unit tests work on very granular pieces of the code, so the number of variables in any single unit test should be small (if it's not, look for a different way to write the code).  You shouldn't even try to run the code as a whole until all the constituent pieces have been validated through unit tests."

    This is very easy to build if you are starting a new project.  What do you do if you have a large, enterprise-sized project that has no unit testing?  You start out with your business layer and build from there. Start with a small method, then you can build up from each class. 

    I worry about trying to get the Lexus when I'm only looking to build a Kia.  I want everything to be perfect when I've gotten something to the point of "release ready".

    When Jeff Atwood (Coding Horror) started posted about formal unit tests, he was struggling to find the "perfect test":

    "You'll get no argument from me on the fundamental value of unit testing. Even the most trivially basic unit test, as shown in the code sample above, is a huge step up from the testing most developers perform-- which is to say, most developers don't test at all! They key in a few values at random and click a few buttons. If they don't get any unhandled exceptions, that code is ready for QA!"

    So I start by building small tests and work from there.  It may take a long time to fully implement unit tests, but I believe this will be to our advantage in the end.

    I offered this solution of adding unit tests and GUI automation to my boss.  He seems to think that this will add significant time to programming and it won't be practical.  The real problem that he doesn't trust that the interface will get a thorough testing.  I told him that there are ways to get this working (possibly using InCisif or WatiN) that would be just like one of the QA team.  He really just can't see how it will work for us. 

    I don't know how I can explain to him that it will end up in his best interest (and mine) to add the unit tests for the business layer and for the GUI.  If not, I guess I'll just have to revert back to programming using BDD.

  • Visual Studio 2005, Why do you taunt me?

    729,942K

    Can you fathom that a program uses this much memory?  I have a Dell Inspiron 9100 with 2G of memory.

    I can't even believe that Visual Studio uses this much memory just to run my application.  I've got a lot of code, but you'd think that it would be able to manage it better.

    Why? 

    I don't even know what I could do to help.  I'm starting to think that building the virtualization environment will be the way to go.

    I've already got Parallels on my machine, why not use it to the fullest extent?

  • IE6 VPC Image - Part Deux

    Because the license to use the original IE6 VirtualPC image was good until April 1, 2007, Microsoft has released another version.  You can download it directly from Microsoft here.

    REF: IE Team Blog 

  • nToolbox - Utility Library Extraordinaire

    After some thought, I've decided to go forth with nToolbox.  Those that have expressed interest, I will be contacting you soon about it.  For those that are interested, you can visit the site and enter your information into the join form!

    I'm excited to get this project off the ground.
     

  • Common Class Library

    I've come to the conclusion that the information that I have to offer to the .NET community is old news.  Someone has already done everything that I've been doing with .NET so how can I best use my knowledge and insight to help in any way possible?

    With all the different code libraries (PageHelpers, Nini, etc...) and applications (like DotNetNuke), there are still some functions that you always use in every project.  I have searched the web for this and haven't found anything yet.  Why not start an open source class library that is a repository for common functions?   I started building my own common library for a weight tracking site I created, but I was using code from all over the web.  Why not actually start something that the community could be a part of and get credit for helping?

    First things first, what will this library do?  I believe that it would be a library that does what the .NET framework doesn't have built in that has use in many different applications.  There would be a good structure for the namespace naming (Math, Security, Strings, etc...). 

    Next would be where to host?  GoogleCode?  SourceForge?  GotDotNet? CodePlex?

    A lot of things need to be answered before even starting, but it seems to me that a lot of people would want to use something like this in their applications, but without the mess of adding it every time to your code. 

    If anyone is interested in helping out or if you have some good ideas, post them in the comments or contact me via email (wright.NOSPAMnet at my gmail REMOVE dot com)
     

  • Your ASP.NET Web Application Subversion Repository Structures

    I've been looking all over for some good, real-world example subversion structures for ASP.NET websites and have only come across a few.  I haven't really used any source control other than storing my code in a repository so it's not just on one computer.

    I've found a blog that has a lot of good examples (http://ariejan.net/2006/11/24/svn-how-to-structure-your-repository/) but there's nothing for specific examples for an ASP.NET.  There's some good ideas I found here (http://discuss.joelonsoftware.com/default.asp?dotnet.12.406052.3) but nothing about the best way to do it.

    I like the idea of the standard branches/tags/trunk, but does that always work on large scale web applications?  I started populating the trunk with the following folders:

    • Database - contains a Red-Gate SQL Compare Snapshot of the database
    • LLBLGen - contains the LLBLGenPro v. 2 project
    • Libs - all .dll files that do not have source code associated with them, such as telerik controls, infragistics controls, browserhawk files, etc...
    • Source - root for any class libraries, projects get their own folder on a per project basis
    • Webroot - the root of the web application project

    I want to put all releases in the tags directory, then any working changes into the branch directory based on the build number (which contains the date).

    I think this is a good way to keep track of everything, but I'm very open to other suggestions. 

  • My Favorite Little Function - FixUrl

    One problem that I frequently run into is trying to get my javascript URLs to point to the correct directory by using the "~" root for an ASP.NET application. Here's a handy function that helps with trying to get to the root of a webapp:

            Public Function FixUrl(ByVal Url As String) As String

                Dim strReturn As String

                If Url.StartsWith("~") And HttpContext.Current.Request.ApplicationPath <> "/" Then

                    strReturn = HttpContext.Current.Request.ApplicationPath & Url.Substring(1).Replace("//", "/")

                ElseIf Url.StartsWith("~") Then

                    strReturn = Right(Url, Len(Url) - 1)

                Else

                    strReturn = Url

                End If

                Return strReturn

            End Function

    So what this function will do is take any URL that is passed (such as "~/admin/user.aspx") will return the proper directory.

    If you are running your application at this URL: http://mytestapp.domain.com/, it will return "/admin/user.aspx". If you are running it locally for testing, such as http://localhost/mytestapp/, it will return "/mytestapp/admin/user.aspx".

    This helps out when you are adding URLs to javascript calls through code (such as window.open('/admin/user.aspx', null, 'etc...) and need to have a generic way to find the root of your application because the tilde will not work in this context.

    Enjoy!

  • Scheduling the Import of data with ASP.NET

    Most enterprise ASP.NET web applications have one thing in common: Data Imports.  Whether it is users, locations or transactions, 95%* of the applications that I've built for large corporations require some external data.  Handling this in ASP.NET has always been troublesome for me, so I thought I'd share my method with you. 

    In the past, I've used Andy Brummer's scheduled timer to execute my scheduled tasks (http://www.codeproject.com/dotnet/ABTransClockArticle.asp) in conjunction with Paul Wilson's keep alive (http://authors.aspalliance.com/paulwilson/Articles/?id=12).  This has been the best way that I've been able to make sure that the code will execute on the proper schedules.

    Basically, a "timer" thread is executed when the application starts and is checked every millisecond.  If the current "tick" is the same as the set scheduled total ticks, then it will execute the import.

    I've been happy with this method and haven't run into any problems with it.

    * estimated guess, I haven't done any in depth studies on it, but I've worked on enough applications to know that it's pretty much everyone.

  • The Hardware of ASP.NET Programming

    Greetings to all! 

    After working with ASP and then ASP.NET, and now with version 2.0, I've programmed on desktops, laptops, and servers.  With the amount of memory and CPU usage that VS 2005 takes to program a large website, I've been looking at upgrading my existing laptop to a newer model.  However, I'm still not convinced that this will solve the problems that Visual Studio seems to have with my hardware.

    I am running a fairly powerful Dell Inspiron 9100 (3.0GHz, 2G Mem, 120Gb 7200 HD) to do my programming.  I have Windows Server 2003 Standard installed on it so I can build and run my development apps using the same environment as the customer (I recommend doing this for everyone, it is nice being able to debug locally instead of trying to do remote debugging onto your test server).  VS still seems to run very slow with this configuration.  I don't think it has anything to do with the hardware, but at this point, I'm willing to try anything.

    I've called Microsoft on three occasions to get the KB fixes from them (after reading this post from the Microsoft Web Dev Team) and none of the fixes have helped at all.  I've have not gotten as many VB Runtime crashes when I try to debug (or switch pages, or click on the File menu, it was completely random when the VB Compiler crashed).  I am still very unhappy with the performance of Visual Studio and wish they would have fixed a lot of the problems that were reported before they went live back in November.  Then again, I guess you get the good with the bad with the new controls and options with 2.0.  Hopefully Brendan will have some good news to report to us, but I digress... 

    I was searching for some blog posts to see if anyone had posted any hardware that they are using to program with ASP.NET and I haven't found much.  

    I don't know if programming on a laptop is better than on a desktop, but I do like being able to take my code home with me to work disconnected.  If anyone else is using the Inspirons, you know that they are beasts!  They can weigh almost 15 lbs. and it becomes a real hassle when you're travelling because you need to take the laptop, along with the power supply (which is just as gargantuan).  I want to look for a laptop that would be used for optimum programming with Visual Studio.  With the new Intel Core 2 Duo CPUs, they take care of a lot of the weight problems because it is smaller than the other chips and don't need as much power (which takes care of the power supply brick issue).  Dell has some newer laptops (XPS series) that I'm interested in, however, I have heard good things about the ASUS laptops for programming (WJ3 to be exact - Coding Horror). 

    Another option would be to build a desktop for programming and development, then Remote Desktop into it.  I think this would be the easiest option since the desktop can be fitted with more memory.  I don't like the idea of my code sitting on another machine while I'm trying to work on it.  It's not "personal" enough.  I need the security blanket of knowing that my code is with me (even though VSS is storing it on the server too). Yes, I use VSS because it was the fastest to set up.  I may move to Subversion sometime in the future, but again, I digress...

    It will just come to your personal preference.  If you're looking for a monster programming machine, you'll just have to get the latest and greatest available. 

    I ask you, what do you have for your setup? 

More Posts

Our Sponsors

Red-Gate!

Proudly Partnered With