Nicholas Head

Filter by APML

ASP.Net Trick: Getting rid of viewstate on DropDownLists

by Nicholas Head 22. February 2009 22:11

If you’ve used ASP.Net for any amount of time, you quickly realize how much it loves to dump into the viewstate. Now, I’m not claiming I’m a saint in this area, but I have been learning as I go to recognize what operations will fill the viewstate and work to prevent them.

One trick I learned recently is to re-bind your DropDownList on every postback, inside of the DropDownList’s Init event handler. You can also pull in the postback value from the Request.Form collection and set the DropDownList’s SelectedValue to what it should be. Observe the following example:

Protected Sub ddlMyDropDownList_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlMyDropDownList.Init
    Dim db = New MyDataContext()

    Dim q = From s In db.States _
            Order By s.StateName _
            Select New ListItem(s.StateName, s.StateAbbrev)

    ddlMyDropDownList.Items.AddRange(q.ToArray())

    Dim r = Request(ddlMyDropDownList.UniqueID)
    If r IsNot Nothing Then ddlMyDropDownList.SelectedValue = r
End Sub

Don’t forget to set “EnableViewState=False” on your DropDownList.

Bookmark and Share

Tags:

asp.net | programming

ASP.Net: Remember, the .Visible property also checks parent’s visibility!

by Nicholas Head 11. January 2009 20:44

new_dotnet_logo I’ve been hit by this a few times, and it’s darn confusing at first, but it makes sense (kinda.)

In ASP.Net, if you reference a control’s .Visible property, it not only checks if it’s been set to Visible = True, but also if it’s parent control is Visible = True. Only then will it return a “True” value back to you.

For example, let’s say you have a PlaceHolder, and inside the PlaceHolder you add a Label control:


   1: <asp:PlaceHolder ID="phParent" runat="server">
   2:     <asp:Label ID="lblChild" runat="server" />
   3: </asp:PlaceHolder>

And then in your code, you write:

   1: phParent.Visible = False
   2: lblChild.Visible = True
   3: Response.Write(lblChild.Visible)

Your response is going to be “False” because the Label’s parent control is not visible.

Just thought I’d share this as a warning to anyone else who might get tripped up on it.

Bookmark and Share

Tags:

asp.net | Microsoft | programming

Past/Current Projects: A-G Sod Farms

by Nicholas Head 24. May 2008 06:08

AGSOD color logo My boss recently posted about A-G Sod Farms on his blog, "Kevin Lewis Blog" and it inspired me to do the same. One of the first projects I was introduced to after being hired by LewisTech was a custom accounting system for A-G Sod Farms. They sell sod in brick & mortar stores, and we recently renovated their ability to order sod online.

I have to admit, at first I was a bit nervous with the scope of the project. I had never worked on anything that large before (and something being used at multiple distant locations, by multiple users.) It was a genuine learning experience, and Kevin helped me every step of the way. In the end, as Kevin's entry attests to, we delivered a great product that has helped the company cut paper usage and be "more green". How about that? A sod company, going green...

So next time you're looking for Sod in Riverside, Sod in Los Angeles, Sod in Sacramento, or Sod in any of their other locations, be sure to check them out. I know that when I purchase a home with Heather (hopefully in the next 5 years?) I will be using them for all my sod needs.

Bookmark and Share

Tags:

personal | programming

VB.Net/C#: How should I throw an exception?

by Nicholas Head 26. December 2007 18:22

This is something that I’ve known for a while, but always seem to forget when it comes to actually implementing it in my code.

When catching an exception, most people catch it as a variable, such as “ex” and then just do a “throw ex” and throw that exception back up the chain. This is probably not what you want. When the stack trace/error information comes back from that exception, it will show as having occurred where your “throw ex” was. This isn’t really helpful if your “try” block contains a lot of code.

Instead, you should just simply write “throw”, without passing a specific exception. This allows the stack trace to show the original location of the error (instead of where you caught the exception and threw it again.) This information is much more helpful when debugging..

And now you know too!

Bookmark and Share

Tags:

programming

Visual SourceSafe 2005 Update CTP

by Nicholas Head 11. December 2007 18:10

I was trying to open a project from SourceSafe under the new Visual Studio 2008, and my list of SourceSafe servers was blank. After a few moments of frustration, I found a CTP (beta) release of a pack of fixes for SourceSafe, and Microsoft suggests you install it before using Visual SourceSafe 2005 in Visual Studio 2008.

http://www.microsoft.com/downloads/details.aspx?FamilyID=FAF41EDD-924D-449F-AEFC-9C86DD499720&displaylang=en

The CTP seems to have fixed my problem, as I can now open VSS2005 projects from VS2008.

Bookmark and Share

Tags:

bugs | Microsoft | programming

My Top Web Development Tools / Add-Ons for Firefox

by Nicholas Head 11. December 2007 16:11

Get Firefox

Over the past few years, I’ve accumulated a collection of add-ons for FireFox that I genuinely use almost daily to do my job. I’ve seen other “top development add-on” lists, and I don’t really agree with all of the items. With that said, here goes my take:

  1. Console2
    http://console2.mozdev.org/index.html

    Allows you to filter the JavaScript Console by type, language and context, compared to the way the console works by default where it just shows everything all in line. You don’t really notice it, because it should’ve been built into Firefox to begin with.
  2. Firebug
    http://www.getfirebug.com/

    Adds an full JavaScript debugging solution to Firefox and much more. Also helps debug your AJAX applications, because it has a network activity view to show you the ins and outs of your page. I can’t live without this add-on, really. Being able to set a breakpoint in my JavaScript and fully explore the DOM/variables while debugging is immensely helpful.
  3. HackBar
    https://addons.mozilla.org/en-US/firefox/addon/3899

    Just recently found this. It adds a toolbar to Firefox that helps you test for security problems with your app, mainly with querystrings/URLs. Gives you tools to automatically increase/decrease values, test for SQL injection, etc.
  4. HTML Validator (based on Tidy and OpenSP)
    http://users.skynet.be/mgueury/mozilla/

    Another “core” add-on I use, that I couldn’t live without. This one adds native HTML validation inside of Firefox. You can use different types of validation, and choose how strict it is with your code. Even checks for accessibility problems. Use this and find out just how syntacticly bad your HTML really is.
  5. LiveHTTPHeaders
    http://livehttpheaders.mozdev.org/

    Like the name implies, shows the live HTTP headers of your page, underneath the “View Page Info” section of Firefox, or via a pop up window in “realtime”. Lets you also change the headers and re-send the request. Kinda like Fiddler, but built into Firefox.
  6. Save As Image
    https://addons.mozilla.org/en-US/firefox/addon/3408

    Again, like it implies, it saves a webpage as an image. Useful for generating “thumbnails” of site designs, bug snapshots, etc.
  7. Server Spy
    http://jacquetc.free.fr/mozilla/exts/ServerSpy/

    Shows (on the bottom of the browser) what web server software the current domain is running. Useful for planning out what web capabilities you’re working with when initially meeting with a client.
  8. ShowIP
    http://l4x.org/frontpage/showip

    Shows (on the bottom of the browser) what the current web server’s IP address is. You can then query that IP address with numerous lookup services to find history, etc. Useful for knowing what server you’re on, or figuring out a domain/subdomain’s structure.
  9. URLParams
    http://urlparams.blogwart.com/share/index.php

    Adds a sidebar to Firefox that makes it very easy to edit GET (querystring)/POST (form) variables, as well as change your referrer, and submit them again.
  10. View Rendered Source / View Source Chart
    http://jennifermadden.com/scripts/ViewRenderedSource.html

    Visually displays the source code of your page, using literally “blocks” of varying colors to represent each element in your code. Each block is collapsable as well. Gives you a quick way to see how deep an element is nested, where it’s nested, what tags are used, etc.
  11. Web Developer
    http://chrispederick.com/work/web-developer/

    One of the most important add-ons. Adds a toolbar to the top of Firefox that has almost everything a web developer could ever want/need for tweaking pages, tracking down problems, editing CSS on the fly, etc… This toolbar has it all. Really, go check it out now and install it. If you don’t install anything else on this page, you need to at least install this one.
  12. Autofill Forms
    https://blueimp.net/mozilla/

    Like it says, it automatically fills forms! Useful for filling out forms with test data repeatedly.
  13. Cache Status
    https://addons.mozilla.org/en-US/firefox/addon/1881

    Adds a section to the bottom of Firefox showing current memory and cache usage, and allows you to right click and reset/clear the caches (RAM/disk.) I use it just to have that cache clearing shortcut.
  14. IE View Lite
    https://addons.mozilla.org/en-US/firefox/addon/1429

    Adds a right-click menu to your page that brings up the current URL in Internet Explorer. Useful for quickly jumping to “the other browser” to see what it looks like over there.

P.S. — An e-mail from Mike at HireAHelper.com prompted me to write this list. Check out his site if you need moving help, landscaping or general help!

Bookmark and Share

Tags:

css | html | JavaScript | programming | windows vista

Flawd Clothing Redesign/Relaunch

by Nicholas Head 3. December 2007 08:52

FlawdClothingRedesign

Worked my booty off this weekend to get Chris’ new design up for Flawd Clothing. I suggest you all check out the site and let me know what you think— from a technical and/or design, etc. point of view. And buy some shirts while you’re at it

Bookmark and Share

Tags:

css | html | JavaScript | personal | programming

Joel on Software -- Why I Don't Care

by Nicholas Head 21. August 2007 06:40

Understand-pandaA perfect example of just why I don’t care is his latest post, an insane rambling about how difficult it was to open the Office 2007 packaging. Come on, Joel. You really couldn’t figure it out? Of course Chris Pirillo jumps in with his two cents, basically rehashing what Joel says, and also point out how bad it is for one of the “world’s leading software developers states this” information. Gimme a break.

When I bought Office 2007 a month ago to install for a friend, opening the box was easy peezy. You just follow the little sticker’s instructions and you’re off. The instructions consist of basically peeling off a sticker and then pivoting open the box. Maybe Joel didn’t get a package with the sticker. I don’t know. But even the most basic student of engineering would figure out that it “pivots open” after one removes the sticker.

While I’m at it, I should point out this genius as well, who claims it took 30 minutes to open the box and took the time to document it on Flickr (no doubt that’s where the 30 minutes came from?) This seal, which they’re implying can only be opened with scissors or a sharp knife, easily tore for me when I pivoted open the box. It was already slightly perforated. Come on, guys. You’re telling me you’ve never encountered computer software packaging with TAPE or PLASTIC?

He also goes on to recommend that people get XP on newer computers, and suggests that Vista should not be used as someone’s primary operating system, due to compatibility headaches. Huh? Care you cite some examples? I can understand a company hesitating to upgrade, since they might need to test some custom software, etc. before doing the push.. but your typical family user(s) are not going to run into troubles. I have no problems recommending Vista to users purchasing a new Dell, Gateway, etc. today.

If you want something to rant about packaging-wise.. why not complain about the way CDs and DVDs are packaged, with the super-tight plastic wrap on the outside, and the one to three stickers found underneath that plastic wrap, which always seems to be stuck on with glue that is not meant for peeling, leaving a yucky substance all over your brand new cover? That’s really lame. If you’re a thief, you’re probably just using a EZ-CD opener or something to quickly rip the cover off and take the disc out.

Bookmark and Share

Tags:

programming | rant

Safari and Selecting SELECT Element OPTIONs

by Nicholas Head 24. July 2007 22:01

This has had me stuck for the past hour. Give me a break. I really hope this is just a bug in the “beta” of Safari.. because it’s extremely dumb.

This Javascript method takes a passed in SELECT element (via ID) and the value you want selected, and will loop through all of the SELECTs options, and select the one whose value matches:

function selectOptionListValue(psElementId, psValue) {
    var OptionList = document.getElementById(psElementId).options;
   
    for (var i = 0; i < OptionList.length; i++) {   
        if (OptionList[i].value.toLowerCase().trim() == psValue.toLowerCase().trim()) {
            OptionList[i].selected = true;
            break;
        }
    }   

                       
    return;
}

Looks simple, right? It kinda is. Works great in Opera, IE, FireFox, etc… but in Safari, nothing happens. Your SELECT gets nothing selected. It turns out, you need to specify the SELECT’s selectedIndex in order to get it to work properly— adding this line before the “return;” fixes it on Safari:

OptionList.selectedIndex = i;

Talk about retarded. Any “Safari developers” out there want to throw in their two cents?

Bookmark and Share

Tags:

Apple | bugs | JavaScript | programming

Are you moving or looking to move soon? Don't hurt your back shifting boxes around-- use HireAHelper to Book Movers Online!

Log in

Powered by BlogEngine.NET 1.6.1.0