Monday, August 16, 2010

Ajax second postback not working in Sharepoint in UpdatePanel


I had an update panel within the Sharepoint where the trigger is set to PostBackTrigger. Any button within the update panel triggered the click event only the first time. After that the click event never got fired until the whole page is refreshed.

This scenario was working in our test environment but doesn't work in our client's test environment. The difference is somewhere with the sharepoint setup.


Windows SharePoint Services JavaScript has a "form onSubmit wrapper" which is used to override the default form action. This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios. However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.

To do this, you may need to register a client startup script which disables this workaround, in addition to resetting the default form action:

Sunday, August 15, 2010

DataTips in VS2010

While debugging we can mouse over on an variable to look at the value or to explore further and we call this as DataTip. In Visual Studio 2010, we can stick DataTips to our code window and drag & drop to any location and the DataTip will hang there. This really facilitates the debugging process.

Run your application in debug mode and mouse over on the variable to pin and click the pin icon. To unpin, just click the unpin icon again in the debug mode.

Google maps - Part 6 - How to get driving directions?

The driving directions can be calculated directions using the DirectionsService object. This object communicates with the Google Maps API Directions Service which receives direction requests and returns computed results. The results can be displayed using the DirectionsRenderer object to render these results.

Saturday, August 14, 2010


Consider that you have created a page named "offers.aspx" which has some item listings and free offers to users when they buy the items.

After the offer has expired you want redirect all the web traffic from "offers.aspx" to "listings.aspx".

If you use Response.Redirect("listings.aspx") in the offers.aspx then it returns a HTTP 302 status to the browser meaning that the "Resource is temporarily moved to another location". This 302 status informs the search engines that the offers.aspx page is temporarily moved. If it returns the same status whenever the search engine crawls, it will ignore the URL for duplicate content.

To avoid this problem and to improve Search Engine Optimization (SEO) .NET 4.0 has got a new method for performing redirections.


This will return a HTTP 301 status "Moved Permanently" to the browser. Because of that the search engine when it crawls the next time will update its URL list.

Alternatively the same can be achieved with .NET 3.5 as mentioned below.

Response.Status = "301 Moved Permanently";
Response.RedirectLocation = "listings.aspx";

Monday, August 09, 2010

Error occured in deployment step 'retract solution' cannot start service SPUserCodeV4 on this computer

I got this error when I tried to deploy a WebPart created using VS 2010 and Sharepoint 2010.


1. Go to Central Administration

2. Open "System Settings"

3. Open "Manage services on server"

4. Locate the service "Microsoft SharePoint Foundation Sandboxed Code Service"

5. Start the service "Microsoft SharePoint Foundation Sandboxed Code Service"

Now try deploying the WebPart and it will deploy successfully.

Sunday, August 08, 2010

Named arguments and Optional Parameters

Optional parameters - the ability to define a function parameter with a default value. When the function is called, the caller can pass the parameter value if not the default value is used.

Named arguments - C# now provides an ability to name the argument and pass the value along with that in a function call.

VB.NET had it for a while. This will be useful when you code with COM API's.

Note: Optional parameters must be specified at the end (after defining the required parameters)

System.Dynamic - ExpandoObject in C# 4.0

The ExpandoObject enables to create new members for an object in runtime. The ExpandoObject was introduced in C# version 4.0.

Note: You must reference System.Dynamic.dll to use ExpandoObject.

Friday, August 06, 2010

Google maps - Part 5 - How to create info windows?

Info windows are really a good way of showing important information about a particular location indicated by a marker. These info windows can display text or can have any HTML inside it.

Tuesday, August 03, 2010

Google maps - Part 4 - How to clear markers on google map?

I had an interesting scenario where I had to clear the markers on a google map. It was quite easy to do in Google Maps API v2. But in API v3 it is not straight forward.

Whenever you create new markers you need to push them into an array. When you need to clear the markers just loop through the array with the markers and remove them.

Monday, August 02, 2010

Google maps - Part 3 - How to create a marker on google maps?

Markers are indicators on google map to denote the places of interest. This post will explain you how to place a marker on google map.

The marker object resides in the google.maps.Marker namespace and takes a single argument, options. Options is an object literal called Marker options that can have several properties of which two are required:

map [Map]
Map is a reference to the map where you want to add the marker.

position [LatLng]
This property indicates the position of the marker and is of type google.maps.LatLng

How to copy a DLL from the GAC

I was trying to copy the System.Web.Extensions dll from the GAC to my application bin folder. You can do that using the following command.

copy "C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\1.0.61025.0__31bf3856ad364e35" C:\temp\project\bin

Sunday, August 01, 2010

How to escape XML text in c#?

Escaping XML text is basically encoding the following symbols (<, >, &, ", ').

This can be done in the following ways.

a) Using Replace function

string xmlData = "I live in \"wellington\" & I love listening to music."
string escapedXmlData = xmlData.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "&apos;");

Note: Replace the & symbol first.

b) Using System.Security.SecurityElement.Escape() method

string xmlData = "I live in \"wellington\" & I love listening to music."

string escapeXmlData = System.Security.SecurityElement.Escape(xmlData);