Archive Page 2

Unbinding events using jQuery

Recently, I was trying to use jQuery’s .Unbind() function to remove an onclick event handler that was was being bound elsewhere, out of my control. (Basically I wanted to suppress a “click to add a new item” link to force something to be read-only in a 3rd party app.) Frustratingly, I could not seem to get the Unbind() to take effect. I knew my selector was okay, because I could change the background-color of the item I was targeting without issue.

Eventually I googled it and found other people with the same problem. Turns out, jQuery only tracks event handlers that have been bound using jQuery. So, if the event handler was bound declaratively in the HTML markup (or output by some other system/framework), Unbind() won’t touch it (doesn’t know about it unless you used Bind() to add it).

The workaround solution is to use .removeAttr(eventname), such as .removeAttr(“onclick”). This worked for me and stopped me from banging my head on the wall any further. Hopefully it helps you, too.

Advertisements

Code block not allowed in your SharePoint Master Page error

"Code blocks are not allowed in this file"

Code blocks are not allowed in this file

I’m posting this now because I just ran into it for a second time, but had completely forgotten what the issue was when I googled it the first time.  So I’m posting it here for my convenience, mostly!

If you suddenly start getting an exception from SharePoint stating that code blocks aren’t allowed in your master page, you need to add a new <PageParserPath> element to web.config to allow the code.  Why this starts happening all of a sudden when the same code block existed in the path previously without the exception, I will never understand.  But the point is, follow the directions in one of these blog postings to resolve it:

http://mystepstones.wordpress.com/2009/02/13/code-blocks-are-not-allowed-in-this-file/

http://svengillis.blogspot.com/2008/03/code-block-are-not-allowed-in-this-file.html

http://dotnetdeveloper.co.uk/blogs/sharepoint/archive/2008/10/10/code-blocks-are-not-allowed-in-this-file.aspx

Can’t find the Site Directory template when creating a site in SharePoint 2007?

Neither could I.  The problem was that I didn’t have the “Office SharePoint Server Enterprise Site Features” site feature and “Office SharePoint Server Enterprise Site Collection Feature” site collection features activated.  Once I activated them, I got the Site Directory as an option as expected.

(Note: if you still can’t see the template after activating those features, try navigating to http://<your_site_root>>/_Layouts/AreaTemplateSettings.aspx and adding the Site Directory template to the available list, then try again.)

SharePoint 2007 Publsihing Site Stops Recognizing Custom Landing Page

Greetings!  It’s been a while since I’ve posted anything, but I’m hoping this may prove helpful to someone somewhere sometime.

Recently myself and a few other SharePoint team members at my site rolled a number of new and updated features into production.  This was a long and grueling affair, and part of the reason was we spent a few hours on this issue I’m about to describe.  We never found anyone describe this problem (or solution) through googling, so I’m either it’s hard to find, or nobody has talked about it.

We have a custom landing page layout and landing page layout content type that we use on a collaboration site.  A previous version was in production and worked fine.  Part of our big production rollout the other day was to update both the landing page layout and content type.  We deployed these two features in our usual way: by updating the 12-hive, de-activating, install -force’ing, and [re]activating the features through stsadm on the command line.  The landing page content type activated fine, the landing page page layout activated fine, but we have a 3rd feature which is for the landing page itself (to dynamically create it through some code in FeatureActivated), and it was throwing an index-out-of-bounds exception when we tried to activate it.

Looking at the exception, and the FeatureActivated code, we narrowed it down to what appeared to this block of code:

SPContentTypeId contentTypeId = new SPContentTypeId(welcomePageLayoutContentTypeId);
PageLayout[] layouts = pubWeb.GetAvailablePageLayouts(contentTypeId);
PageLayout welcomePageLayout = layouts[0];
page = pubWeb.GetPublishingPages().Add(dcsLandingPageFileName, welcomePageLayout);

Specifically, to the layouts[0].  This seemed to indicate that GetAvailablePageLayouts was not returning our custom landing page layout associated with our custom landing page content type.

We spent some time re-deploying all 3 features again with no success at that last step.  We made sure that the content type looked up to date, that the Master Pages and Page Layouts gallery had the most recent version of the page layout, that the page layout was correctly associated with the landing page content type, that we had deleted the old landing page from the Pages library, etc., etc.   Nothing we tried helped.

Eventually through some googling, another member of my team found this installable feature that lets you do a number of things, among them to enumerate all the available page layouts to the command line.  The feature is described here http://stsadm.blogspot.com/2007/08/enumerate-available-page-layouts.html.

Once we had installed and ran that feature, we discovered that our custom landing page layout was not showing up in the list.  We re-verified the the site settings that the page layout was in the gallery and was associated to the page layout content type, and that the content type was installed correctly, etc., but nothing seemed to help.

Then we finally had a break-through:  looking at the enumerated available page layouts listing from the stsadm tool, we noticed that not only was our custom page layout not showing, but a number of other page layouts were missing, all of which were out of the box SharePoint Publishing content types!  We determined this by comparing the enmerated page layouts list on our “broken” site vs. the list on another site using the same lading page that was functioning correctly.

This lead us to the Site Collection Features and Site Features pages to verify that publishing was enabled.  It was.  We were further stumped.  On a whim, we decided to try de-activating both features and re-activating them.  Guess what–this solved our problem!

So even though publishing appeared to be enabled, somehow, bizarrely, it was actually broken.  Flipping the switch on and off resolved this, after a few hours of face-palming and much stress.  I hope this tale may help you if you ever run into this.  It’s worth a shot!

Top 20 Essential Firefox Add-ons for Web Devs

Here’s a handy listing of 20 Essential FF Add-ons for Web Designers (and Developers, IMHO).

Some of these I already know about and use a few (Firebug, Web Developer, IE Tab, YSlow), but I intend to add a few more to toolbox (Window Resizer, Page Diff, CSS Viewer).  The rest seem to either not very useful to me personally, or are duplicates of functionality I already get from Firebug and/or Web Developer, but hey, YMMV!

Be sure to hit up the hyperlink above for the full blog post!

Breaking news, C# 4.0 finally catches up to Classic VB!

This bit of nostalgic humour will be lost on n00b developers, or anyone lucky enough to have missed out on developing in VB6 (or older–I think these features were introduced in VB4 or 5, but can’t recall for sure).

C# has finally decided to embrace optional parameters and named arguments!

That’s right.  It only took 4 versions to catch up to what you were doing well before the .NET days.  Oh well, better late than never!

Of course, you could at least partially work around this in C# 3.0 and older by putting the method implementation in the most verbose signature version of your method and creating any number of overloads needed.

Using the example from the blog posting linked above (please read it before continuing), you’d create:

//main method with all the parameters and full implementation
public void SomeMethod(int a, int b, int c)
{
/* put the actual implementation here */
}

//overload to omit the c parameter and default to 100
public void SomeMethod(int a, int b)
{
SomeMethod(a, b, 100);
}

//overload to omit the b and c parameters and use the defaults 50 and 100, respectively
public void SomeMethod(int a)
{
SomeMethod(a, 50, 100);
}

However, if we then want an overload that omits the b parameter only, we run into trouble.  If we try this:

public void SomeMethod(int a, int c)
{
SomeMethod(a, 50, 100);
}

We would end up with a compile error, since the signature of this overload would be the same as the first overload I declared above, namely:

public void SomeMethod(int, int)

If a, b, and c were of different datatypes, we could declare any combination of parameters, but this example of all int’s does demonstrate the weakness of this approach, and why the new optional parameters and named arguments is so exciting!

Patterns and Practices Application Architecture Book v2.0

From Scott Gutherie: Patterns and Practices Application Architecture Book is now available online (for free) and in print: http://bit.ly/dzpvJ

 


Scott’s recent tweets…