Code Nuggets: A Side-effect of Using DropDownList AppendDataBoundItems With Databound Items

Picture this: You have a webform with two DropDownLists, both of them are databound to some data you get from a database. Now the first DropDownList’s selection determines the contents of the second dropdown. So you simply do a AutoPostBack = true for the first dropdown and populate the second dropdown in the handler function. Right?

But wait. What if you are required to put in a static item in the dropdown? Something like “– Please Select –“ as the first item in the list to force the user to make a conscious choice. Hmmm, so you look around and find the nice little property named AppendDataBoundItems that will take care of that. All you have to do is declare the first (static) item in the Items collection in the designer (or put a <asp:ListItem> tag inside your <asp:DropDownList> tags) and set AppendDataBoundItems to true. This nice little property tells the DropDownList to add the databound items after the statically declared items, so you can have your happy little “– Please Select –” in your dropdown.

The Side-effect:

The side-effect becomes evident when you play around with your two dropdowns. Its immediately clear that something is not quite right. The AppendDataBoundItems property forces your dropdown’s items from the previous postback to be treated as static objects onthis display. Sort of where you get an ever-growing second dropdown with a hangover from the postback, which is clearly not what you wanted in the first place!

Continue Reading >>

Advertisements

(Tech)LifeDotCom

Though I moved from Blogger quite a while ago, but just for old times’ sake I had kept my account active. For those who are new to this blog, I maintained a blog at Blogger quite some time, which can still be found here. I have now decided to turn into the technical version of LifeDotCom, aptly titled (Tech)LifeDotCom.
(I believe that’s apt enough, don’t know what you guys would think.)

Initially I wanted a separate dynamic page on this WordPress blog, but it only allows you to have static pages, if you need. Means you can have only one blog-like dynamic page and several static pages (which you can see if you look at the top of this page). So putting posts on a static page in the manner of a blog was a major pain in the backside, which was gawking at me. The solution I finally arrived on? Reuse Blogger.

I gather that Blogger has quite mended its ways with the glitches that were apparent in the Beta stage. So (Tech)LifeDotCom would mainly contain some thoughts about the tech landscape, with some snippets of code, and possibly (some) full-fledged tutorials. I only wanted to build a repository of snippets and thoughts and efficient ways of (technically) doing things which would be accessible to me, but I realize that shunning the community on little goodies is not a good thing. I wouldn’t promise to update that blog as regularly as I do this one (does that mean never at all?), but I’ll be posting updates now and then.

Most of the people that (still) read my blog are not technical at all, but hey, I updated the brief description at the top!

My Something Worthwhile…

Before coming to Singapore, when I was free in my last days in Karachi after leaving my job, I was involved for a while in the redesign of ApnaKarachi.com. A major part of the overhaul was the new section of ApnaKarachi Maps which provide street-level maps of the city of Karachi. I was in charge of developing the back end of the maps section and as well as managing the people involved in it. We planned to finish and deploy the site for the public before I’d leave for Singapore, but tweaks here and there made maps a little late. I completed the major chunk of the work when I was in Pakistan, and while in Singapore I generally just made things work accommodating the “wish list”.

The ApnaKarachi Maps are now live for sometime now. The site itself has been redesigned and different sections added to it. Its now “bigger and better” in the true sense.

The basic motivation behind the Maps was that Pakistan per se doesn’t have any worthwhile representation in major map sites like Google or Yahoo! Maps, so we intended to provide that kind of information and facility to our people. We have just started with Karachi, other cities would definitely on the way.

As everybody knows that I’m a pretty unassuming guy and I generally don’t do any kind of self-embellishment, but the purpose of this post is to solicit feedback and ideas to make the Maps better and more useful. It’s seldom that we do something worthwhile for our country/people, and while such an initiative is going on and you can be a part of it, then you must.

Please also spread the word around. This service is solely provided for the benefit of people, so the more people use it, the more we would be in the position to improve it.

PS: Don’t forget to say some nice words to me!

The 7th Up

The Windows Internet Explorer 7 has got to be one of the dumbest browser I have ever used. Yep, dumber than Konqueror or Safari. I mean, I just spent the last five minutes searching for the “History” button.Internet Explorer 7 I could not find it anywhere on the toolbars, nowhere on the menus, and as despair was starting to hit home, there it was, a little arrow to the right of the “Forward” button. Pretty nifty, eh? NOT AT ALL! As far as I am concerned, being a “user”, I need the basic functionality visible to me, and I wouldn’t want to grope around to find the things I am looking for.

And the menu-bar-appears-when-alt-is-pressed mechanism is totally uncool. I am definitely not comfortable with web pages sliding down.

Buh, the aero look is a little cheesy. My advice: I really don’t see any reason for anyone to upgrade to IE 7. They’d be better off using Firefox. If any one is out there who is still loyal to Microsoft, then they should download the service pack 2 for IE 6. That’d make IE 6 better than its successor, and of course, without the sugary coat.

Note to self (dynamic controls ASP .NET)

…when populating a dynamic control (such as a dropdownlist dynamically), keep in mind the states of the page. Add that population before the Page_Init event for it to work correctly…

Warid and some retrospection save the day!

Being in Pakistan sucks magnanimously when you have a deadline the next day and in the middle of the night just when you are completing your report that is to be sent, your internet cable network dies on you. The little red cross or the yellow triangle with an exclamation mark that appear on the two little monitors on the right bottom of the screen, are incredibly annoying. Doesn’t help either if the only internet cards you had bought were in the *early* days of the internet and since then have been relying on the cable or the hours you had hacked. You don’t even know if the dukaan on the gali ka nukkar sells internet cards anymore…

That’s where some common sense and your techy, inquisitive nature save your neck.

Enough of an introduction, the above scenario was happening to me a few hours ago. The internet had died, all my friends had migrated to dsl, and using internet cards seems positively non-geeky to me. I had to use the internet for an email, but it had to be in style.

And this is where the common sense kicked in. My faithful Razr, and the old Warid SIM, combined to give me a truly streaming internet experience. For those of you for whom connecting the PC to the internet via a cellphone is still a far-fetched idea, think again. It is as seamless as it gets. However, you’ll still need a cable that connects your phone to your PC, a CD with its drivers, and GPRS enabled on your SIM. Oh, and some common sense would most certainly help.

You wouldn’t need to setup any new dialups, no hassle. Just remember to discard any proxy settings if enabled on your network, and of course, disable the ISA Firewall client for Firefox to work properly; if you indeed follow these and decide to be a little cool.

PS: This post is written while connected to the internet through a cellphone, and the previous email was sent using this method also. And it has taken a considerable lot of time!

Defaced

b.i.t.s. website was defaced yesterday morning by some Turkish hacker named Metlak. A quick search at Google revealed that this guy has been pretty busy defacing websites, with some nationalist message plastered every time on websites he defaces.

The hosting company people said that this attack was carried out through Perl injections. Perl is a server side programming language extensively used for web scripts and to process data passed via the Common Gateway Interface from HTML forms etc. This was the image that was posted on the page with some crap in Turkish (and some poem):

atam.gif

This guy, Metlak, turns out to be a typical teenager script kiddie (source: internet) bent upon getting his message across through such means. b.i.t.s. just happened to be a website that he used.

Not much damaged was done, only the index page was affected. Everything else was in perfect order including Sabeen‘s blog. It was a matter of minutes that the website was fixed, and Sabeen’s blog messed up.

So out of this whole thing, Sabeen’s blog turns out to be the only casualty! 😛