Moving Blog… January 11, 2009
Posted by Nate in : General , add a commentMy blog will be moving to a different domain. You will be able to find it here.
Popularity: 16% [?]
ASP.Net HowTo: Handle Dynamic Show/Hide Controls Within a FormView Template January 22, 2008
Posted by Nate in : Programming , add a commentI had a very simple problem in one of my ASP.Net projects. On one of the pages, I have a TextBox control that needs to display depending on the selected item within a DropDown control. The problem I encountered was that the FormView control did not load it’s child controls at the time I expected, which caused a minor bug in my testing. Here’s a bit of how it started and some of my tests…
To handle the logic of showing/hiding the textbox, I created the following method on the page:
private void ShowHideRecurInterval()
{
Control list = FormView.FindControl(“RecurrenceList”);
DropDownList ddl = list as DropDownList;
Panel recurPanel = FormView.FindControl(“RecurrencePanel”) as Panel;
TextBox recurValue = FormView.FindControl(“Interval”) as TextBox;
Label recurDesc = FormView.FindControl(“RecurDesc”) as Label;
if ((ddl != null) && (recurPanel != null) && (recurDesc != null))
{
string text = ddl.SelectedItem.Text;
if (!(“None”.Equals(text)))
{
recurPanel.Visible = true;
recurDesc.Text = StringUtils.RecurrenceUnit(text) + “s”;
}
else
{
recurPanel.Visible = false;
recurDesc.Text = “”;
recurValue.Text = “0″;
}
}
}
The above method centralized my logic for determining when to show or hide the textbox, and how to do so. Now all I had to do was determine the right times to call this method. Off the top of my head, I knew there were at least two cases where this code would need to run. 1) if the user changed the dropdown list (I may then need to show or hide the corresponding textbox. 2) when the page loads, or posts back (I need to make sure the textbox always displays appropriately depending on the SelectedItem in the dropdown.The first approach was very simple, and had a bug that I found during my dev testing. To handle the first use case, I attached a delegate to the SelectedIndexChanged event for the dropdown. The delegate method just called my ShowHideRecurInterval() method. As so:
internal void RecurrenceList_SelectedIndexChanged(object sender, EventArgs e)
{
ShowHideRecurInterval();
}
To handle the second case, I called the ShowHideRecurInterval from Page_Load():
protected void Page_Load(object sender, EventArgs e)
{
ShowHideRecurInterval();
}
This is where I found my issue/bug. I found that the TextBox was not always displaying when it should. For example, when the FormView switch modes, say from ItemTemplate (View mode) to Update mode, I found that the above code was called, but my null check on the DropDown was failing (the dropdown control was null basically, which means it wasn’t located as a child control under the FormView control). Here is where the code was failing:
if ((ddl != null) && (recurPanel != null) && (recurDesc != null))
{
A quick diagnosis found that I placed my call to ShowHideRecurInterval in the wrong place. I needed to ensure that the dropdown was initialized properly first, with the selected value set already. In the above case, the FormView had not completed switching modes (from ItemTemplate to EditItemTemplate for example).
I next tried moving my call from Page_Load to different page lifecycle events, to see what would work.
Moving the “ShowHideRecurInterval()”call to Page_LoadComplete did not work. The ASP.Net lifecycle documentation for 2.0 suggests that all controls, including all child controls, would be done loading at this point, which I guess is not true for all child controls under a FormView control. Here was the call:
//protected void Page_LoadComplete(object sender, EventArgs args)
//{
// ShowHideRecurInterval();
//}
Next, I tried moving the “ShowHideRecurInterval()” call to a delegate for the FormView ModeChanged event:
//void FormView_ModeChanged(object sender, EventArgs e)
//{
// ShowHideRecurInterval();
//}
Finally, I found a solution that worked in all cases. I moved the call to the PreRender event for FormView:
protected void Page_Load(object sender, EventArgs e)
{
FormView.PreRender += new EventHandler(FormView_PreRender);
}
void FormView_PreRender(object sender, EventArgs e)
{
ShowHideRecurInterval();
}
This enabled the FormView to complete changing modes and initialize & load the DropDown (which I needed to happen first). I could then remove the delegate/event handler for the SelectedIndexChanged event on the dropdown (no longer needed, as long as I keep the autopostback turned on for that DropDown control).
Now I seem to have a working solution that is centralized in one place, and not getting called multiple times during a single page load or postback. I could also investigate moving the code to a different event in the page/control lifecycle, but this solution works for this small project.
I have now spent more than twice the amount of time just writing this up for the blog….. ![]()
Popularity: 56% [?]
Slow Laptop. CPU SpeedStep Partial Culprit January 9, 2008
Posted by Nate in : Tech , add a commentI have a laptop that I use for work. A few weeks ago I noticed that it really slowed down dramatically, and it is really slow to launch new windows/applications.
After doing some research I found that my laptop was running at a reduced CPU speed. Apparently, this was due to SpeedStep technology which automatically reduces the CPU clock speed when on battery power (i.e. the laptop is not plugged in). It does this to help conserve the battery power. However, when at home or at the office (which is almost all the time), I always have the laptop docked and plugged in. SpeedStep and Windows XP are supposed to automatically boost the CPU clock speed to normal (max speed) when plugged in. The problem in my case was that it did not boost my speed back up to normal when the laptop is plugged in. My laptop has been running at reduced CPU speed for about 3 weeks before I found this problem.
Here are the steps I took to troubleshoot and resolve that problem:
- Checked my current CPU speed (via right-click on My Computer > Properties). I noticed that the laptop was running at 733 MHz, when the true CPU speed was listed at 1.73 GHz.
- Opened the Power Options applet (via Start > Control Panel > Power Options).
- Changed the current Power Scheme to “Always On” - to disable the SpeedStep feature.
- Checked the current CPU speed again (step 1) and noticed that the CPU is now running at 1.73 GHz.
Unfortunately, this is just a temporary fix, as it disables SpeedStep altogether. If I use my laptop on battery power, my CPU will continue to run at full speed and chew up battery very quickly. I did a test and reverted my Power Scheme back to “Portable/Laptop” thinking it may revert SpeedStep back to normal (and see that I was plugged in), but it did not. It just reverted the CPU back down to 733 MHz even though I was docked and plugged in.
From speaking with some co-workers, it sounds like there was a fix for this in XP SP2 (which I have), but that some bug still exists. I can only hope that Microsoft is working on the issue and will release a fix.
Popularity: 52% [?]
Testing the WPhone plugin for WordPress January 4, 2008
Posted by Nate in : General , add a commentI am writing this post from Penn Station in NYC.
So far, the WPhone plugin makes it very easy to navigate the administrative features of WordPress using a phone, iPhone or other mobile device (I am using a smart phone pda)
The admin pages load really fast compared to before. I will post another update as I experince more of the features.
Popularity: 54% [?]
New iPod Touch October 31, 2007
Posted by Nate in : General , add a commentI am excited to try out the new iPod touch. This new iPod looks and feels much like the iPhone. Not that I have one, but a friend of mine has one, and it is very cool.
Popularity: 57% [?]
Enterprise Library 3.0 April 26, 2007
Posted by Nate in : Programming , add a commentMicrosoft’s patterns & practice’s group have released the next version of the Enterprise Libraries (EntLib 3.0). This release has added a new application block (Policy Injection), which seems to be a validation module of sorts (apply validation rules to your code via a config file).
Popularity: 56% [?]
wowsmack.com beta released November 13, 2006
Posted by Nate in : Projects , add a commentThe first beta (or Alpha) release of wowsmack.com has been posted. It is still very much a work in progress, but it is getting there very quickly. Check out the beta site here.
Popularity: 60% [?]
New Project: wowsmack.com November 10, 2006
Posted by Nate in : Projects, World of Warcraft , add a commentI started a new web project recently. It is “World of Warcraft” related; and will hopefully help the raiding community out. The project was originally called “Raid Manager” but was renamed to “wow smack” - something a little less boring (but also less meaningful).
The short - it is a WoW raid management / scheduling site (much like Raid Space, but with a lot more features). My guild has been using Raid Space for some of our raids - and the site was Ok (it lacks a lot of basic functionality that I would consider necessary). Once the author mentioned he was no longer developing / supporting the site, I felt it was time to try and ramp up my own. The development for the first release is almost done, and I expect to have an Alpha or Beta release very soon.
So you can check out the project site (& status): http://wowsmack.com or the development log at http://blog.wowsmack.com
Popularity: 88% [?]
MAPI Message.Send() Error (MAPI_E_NOT_INITIALIZED) September 26, 2006
Posted by Nate in : Programming , add a commentI ran into an issue at work today (actually, the issue found me is probably more correct). Somebody started getting an error message from a VB application my department wrote (a long, long time ago), and the application wouldn’t send email messages anymore (it just bombed out - which is a technical term). This is a VB 6.0 application that is using MAPI and CDO to communicate with Exchange. Outlook 2003 is also being used. (more…)
Popularity: 100% [?]
Funny Stuff August 23, 2006
Posted by Nate in : Stuff , add a commentJust cruising the web and found this tidbit (thanks to my brother-in-law). Funny site to browse while you are waiting for a plane.
Popularity: 57% [?]