Rick van den Bosch - Blog

... on .NET, software architecture, software development and whatnot

Recent Posts

Tags

News

  • Live space

    Photo blog

    Follow me at twitter

    Rick  van den Bosch

    LinkedIn profile

    Add to Technorati Favorites

    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Community

Email Notifications

Blogs I read

Interesting links

Archives

March 2008 - Posts

Error adding an OleDb Data Connection to Visual Studio Server Explorer

The error I'm getting when setting up an OleDB connection to an Access database* via the Server Explorer in Visual Studio 2008 is Incorrect Add Connection screen'Format of the initialization string does not conform to specification starting at index 0'. The screen doesn't display the way it should be displayed, as you can see in the screenshot on the left.

There is a possible fix at svenM's blog (it's about checking the existence of a key in the registry called 'ProgID' and the default value, as you can read in this article), but this doesn't seem to work for my situation.
It took me some time trying lots of  'possible fixes' (like the registry change, attempts to (re-)install mdac, uninstalling and installing Visual Studio, and so on) . None of them helped. I even went through all four pages of this lengthy thread, but to no avail. The only thing I haven't tried yet is the most rigorous solution: format the disk and start with a fresh install.

I'm getting annoyed over here..., if you have any tips: let me know.



* I won't go in to whether an Access file is or is not a database ;). And although I generally wouldn't consider Access as the database solution for an important business application, I do think it does have its pro's in specific scenarios, like for a relative small web application.

DropDownList SelectedIndexChanged doesn't trigger UpdatePanel in SharePoint 2007 SP1

A week ago I had a nice page that was hosted in SharePoint and, among others, contained an updatepanel with a dropdownlist in it. Everything worked, and all was well. Because our testers had found some issues we had delivered two newer versions to our development environment. In the last version they found an issue that wasn't there before: selecting a different value in the dropdown did not only update the updatepanel, but resulted in a complete postback. My first idea was: that's an easy one, I'll check the triggers. Boy, was I wrong...

A few hours later, we had everything working again. But rebuilding the entire usercontrol didn't solve the issue, and neither did changeing all available settings for all controls ;). Weird thing was it did work when outside of a SharePoint environment. After some extensive searching, I found a post on Brian H. Madsen's blog, called Using DropDownList with an UpdatePanel in MOSS 2007. As it turns out, SP1 introduces a bug for working with dropdownlists, making that the SelectedIndexChanged event isn't captured by the update panel. Brian's post contains the code below which, if placed in the page_load, solves this issue:

if (this.Page.Form != null)
{
    if (this.Page.Form.Attributes["onsubmit"] == "return _spFormOnSubmitWrapper();")
    {
        this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
    }
}

ScriptManager.RegisterStartupScript(this, this.GetType(), "UpdatePanelFixup",
    "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);

ModalPopupExtender in SharePoint - part II

As I said earlier, we didn't test our solution to using the ModalPopupExtender in SharePoint in all situations. Today we made a start to do so. To indicate our successrate: we now use window.showModalDialog with some extra pages...

Lets go through some of the problems we encountered.

  • Placing an UpdatePanel around the entire UserControl (with default settings) makes that the entire UserControl is posted back, even when it is a control inside a nested UpdatePanel that posts back. The ASP.NET controls have no problem with this, but the SharePoint InputFormTextBox set to RichText does. The toolbars are not rendered, and the entire HTML is shown. Setting ChildrenAsTriggers would disable this behaviour (it does with default ASP.NET controls), because in that case only the nested UpdatePanel is posted back. Unfortunately we didn't get to test that.
  • The SharePoint page layout doesn't render properly when using the XHTML Transitional doctype. Probably nothing a redesign of the masterpage (and maybe some controls) can't handle, but it seems you need time and budget for that. ;)
  • The background wasn't always completely grayed out using the BackgroundCssClass. Sometimes a ribbon of say 10 pixels was shown normal, sometimes the entire background was displayed normal. And clickable! That's not what we would like to use a modal popup for.

Especially the last problem made us eventually switch back to an oldskool JavaScript solution, although we did mix it with some UpdatePanels. The Ajax modal popup sometimes did its job, but not all of the time. We couldn't quite put our finger on it. When a solution doesn't feel stable and there isn't much time, you should / sometimes have to revert to proven technology. The problems we encountered are solvable, or at least I think so. We didn't have time to prove they are. At least not this time... ;)

Getting the ModalPopupExtender to work in SharePoint 2007

Getting the ModalPopupExtender from the Ajax Control Toolkit to work (decently) in SharePoint was not exactly a walk in the park. With a default SharePoint installation, the modal popup is partly positioned 'outside' of the page (you only see the bottom right part of the popup in the top left corner of the browser). Postbacks are not executed or executed poorly and the page gets garbled up. A possible solution for the positioning of the popup is to set the X and Y property of the ModalPopupExtender. Downside is you never know (for sure) if the popup is positioned inside the visible part of the browser because of things like non-maximized browser, different resolutions and so on.
Today we seem to have solved our issues with the ModalPopupExtender in SharePoint. We haven’t tested it in all scenario’s yet, but we’ll get to that. At this point everything looks the way it is supposed to. And it seems to work, too… ;).

The extra steps we took to make these two play together the way we wanted them to, besides the usual steps to make Ajax work in ASP.NET 2.0, are:

* Because of our setup with close-images that postback (because we have to clear controls and that sort of stuff) and more, we couldn’t use the TargetControlID property for the ModalPopupExtender. Well, we could, but that would result in the background not being displayed properly half the time ;). This can be solved by setting the TargetControlID to a dummy control (like a hidden one) and showing the popup from code.

** We have a usercontrol with several usercontrols in it. This one usercontrol (the parent) was added to a page. The normal (postback) controls on the usercontrols didn’t work after one of the modal popups was shown. And I can image neither would any other 'normal' controls on the page, but we didn't encounter this scenario. The problem was the page would freeze with a message in the taskbar stating ‘The page is busy submitting data to the server’ directly after an Ajax postback. The controls that performed a 'normal' postback did nothing: the serverside code just was not executed. We solved this by putting an updatepanel around everything inside the usercontrol. That way the normal controls would postback in an ajaxy way too, apparently solving the 'The page is busy' message.

We'll be testing this solution over the next few days. If any problems pop up, I'll keep you posted.

New feature: subscription by e-mail

It is now possible to get updates from this blog through e-mail (nice feature, feedburner). Updates will be sent once a day, but only when new items are available.

Curious? Subscribe here!

I8 converter - Download (sourcecode available)

One of my colleagues pointed out the new Fine-grained password policy feature in Windows Server 2008. As you can see in this post at The Sean Blog, some values have to be entered in the I8 format, which isn't very user friendly. Because of that, he asked me if I could whip up a tool that converts days, hours, minutes and seconds to the I8 format. I quickly put together this small tool for him. It hasn't been tested extensively, but I think it might be of some use to some of you.
For example, I used longs to store the info. When wanting to calculate huge values, this won't work of course. This could be improved by using the multipliers divided by for instance 10,000,000 and add the appropriate amount of zeros (7) to the string after calculation, so the numerical value stays a lot smaller. Still, I think it does what it should do at this point. You can find the sourcecode over here, of if you would like te change anything: be my guest. Let me know if you find bugs or add cool features: I would like to know.

Info taken from Technet:

When you use the ldifde command to create PSOs, you must enter the values of these attributes in I8 format, which stores time in the intervals of -100 nanoseconds. (Schema: attributeSyntax = 2.5.5.16 (I8).) Windows Server 2003 Default Domain Policy employs this exact time unit for its corresponding time-related attributes. To set these attributes to appropriate values, convert time values in minutes, hours, or days to time values in the intervals of 100 nanoseconds, and then precede the resultant values with a negative sign.

Links
Tool: http://www.rickvandenbosch.net/downloads/I8Converter.zip
Source: http://www.rickvandenbosch.net/downloads/I8Converter Sourcecode.zip

(Single-Entry, ) Single-Exit, my 2 cents

As a reaction to this article at Peter Ritchie's MVP Blog, I thought I'd give my two cents on having a single exit point for methods. Here we go...

When writing code, I always create only one exit point except for the occasional throwing of an exception. Most important for me is to always know where your code (really) stops. In case of long and complex methods there's a chance you're going to miss a return statement when scanning through a method. That way you could end up studying code not even applicable to the situation, while missing the real point. I do think there is no real reason to hold on to creating methods with a single exit point other than personal favoritism. This feels the same like using curly brackets with an if-statement that is followed by only one statement. I always use curly brackets, but there are lots of developers who don't.

To answer the questions at the end of Peter's post: Yes, I do generally follow the Single Point of Exit From Methods Principle, and I do ignore it for exceptions.


BTW: the SESE version of the first method in Peter's post could be a little less (cyclomatic) complex:

public static int CountCommas(string text)
{
    int result = 0;

    if (!string.IsNullOrEmpty(text))
    {
        int index = text.IndexOf(',', 0);
        while (index > 0)
        {
            result++;
            index = text.IndexOf(',', index);
        }
    }

    return result;
}

Now available: PowerCommands for Visual Studio 2008

One of the most annoying things in Visual Studio (to me) was the fact that complete solutions (solution folders, projects, regulare folder)  would be expanded upon opening. And with big solutions, that isn't too much fun. There are macros available online, but the ones i found were pretty slow. This is only one of the things that the PowerCommands for Visual Studio 2008 solves for you. But there is more. Much more!

A quick top five of my favorite functions:

  • Collapse projects
  • Copy & paste references
  • Open Command Prompt (at the location of the file you execute it on)
  • Remove and Sort Usings (for all classes in a C# project)
  • Close All (on a tab)

To get the PowerCommands for Visual Studio 2008, or to learn more about all the features in there, visit them over here.

By the way: this fairly new website (the Visual Studio gallery) was released quite silently by Microsoft. It contains lots of products that aid developers while working in Visual Studio, together with some Extensibility stuff. Have a look over there! Another tip: the VSX team blog. It might be a nice one to keep track of new releases of new Extensibility products. There's a post over there about the PowerCommands, too.

Enjoy!

Short personal update - March 2008

This weekend we got back from a skiing trip we went on with the school my girlfriend works at. We had a great time! The kids were great, and so were the teachers and the Huski people who were there to teach the kids how to ski and snowboard. If they need an extra pair of hands next year, I hope they'll consider me: I'd be happy to join them.

I ordered my new phone this weekend. I arrived home 10 minutes ago, and the postman had beaten me to it: there was a note saying they will try delivering my phone again tomorrow. I hope they'll come when I'm at home, so I can go ahead and play with it. Boys will be boys, right? And then there's the combination boys & toys.... ;)

My 'old' phone is going to my girlfriend, because some m***erf***ers broke in and stole lots of stuff, like our laptop and her PDA phone. I can't understand why people do such a thing, why they just take something of someone else. I guess some people don't have a bit of decency in them... ( </angry mode> )

We will be looking for a new laptop, any tips are welcome. And, of course, I'm open for buzzing / WOMM ;)