Monday, October 29, 2007

How to remove SharePoint context menus selectively

I need to figure out how I could I selectively remove some Standard SharePoint list context menu. For example, most of the list context menus contain Edit Item, Delete Item etc. assume I have to keep the delete menu but need to strike out the "Edit Item". How can we do that?


Go to the page settings. Add a new content editor web part into he page and go to the settings of this content editor web part. Open the source editor. Put the following scripts on it.

<script language="javascript">

function Custom_AddListMenuItems(m, ctx)


var strDelete="Delete this Item";

var imgDelete='';

var strDeleteAction="deleteThisSelectedListItem();" ;

CAMOpt(m, strDelete, strDeleteAction, imgDelete);

// add a separator to the menu


// false means that the standard menu items should also rendered

return true;


function deleteThisSelectedListItem()


if (! IsContextSet())


    var ctx=currentCtx;

    var ciid=currentItemID;

    if (confirm(ctx.RecycleBinEnabled ? L_STSRecycleConfirm_Text : L_STSDelConfirm_Text))


        SubmitFormPost(ctx.HttpPath+"&Cmd=Delete&List="+ctx.listName+                    "&ID="+ciid+"&NextUsing="+GetSource());





Finally make the content editor web part invisible. Voila!

Saturday, July 28, 2007

Posting client side data to server side in ASP.NET AJAX

Often we need to bring some client side data (e.g. javascript variable's value) into the server side for processing. Doing this usually done using hidden fields- registering hidden fields from server and modifying the values at client side using javascript and finally bringing back the modified value to the server along with a post back. I was going to do this same task from within an ASP.NET Ajax application. And I found that if using a handler for client side add_beginRequest is not sufficient to accomplish this task. The reason is the begin request is fired by the AJAX after preparing the request object. So changing the value inside this method will not reflect the value at server side.

Here is the way how we can resolve this problem. First of all we are going to register a hidden field from the server side

void Page_Load(object sender, EventArgs e)


if (!Page.IsPostBack){

ScriptManager.RegisterHiddenField(UpdatePanel1, "HiddenField1", "");



Now at the client side, we need to register a handler for the begin_request event of ASP.NET AJAX client side script manager.




Now, we need to modify the request object (inserting the data that we need to bring at the server end) just before it gets posted into the server. Here is how we can do it.

function onBeginRequest(sender, args)


var request = args.get_request();

var body = request.get_body();

var token = '&HiddenField1=';

body = body.replace(token, token + document.getElementById('someElementID').value);



Here we are opening the request object and modifying the request body by inserting the value found at a text input element.

Now at server end you will find this value

void Page_Load(object sender, EventArgs e)


if (!Page.IsPostBack) {

ScriptManager.RegisterHiddenField(UpdatePanel1, "HiddenField1", "");


else {

string etst = Request["HiddenField1"]; // reading the value here!


That's it!

Tuesday, July 24, 2007

Sys is undefined – in AJAX

Sometimes, funny mistakes makes me crazy...

Today, I was facing this error during playing with a simple AJAX application. Actually the application has an update panel and couple of controls in it. And it is working smooth. But when ever, I was going to write some client side javascript onto the page I was facing the error. Here is the code.

<head runat="server">
<script type="text/javascript">
function pageLoaded(sender, args)
</script> </head>

Spending 30 mins I did not find a good solution into the internet. Later I tried to move the script block from the head section to the body section (after the script manager declaration) and I found it is working! I hope it will save some of your vital mins…

<head runat="server">
<title>Untitled Page</title>



runat="server" >





function pageLoaded(sender, args) { alert('works'); }


Friday, July 13, 2007

This Blog has been posted from Word 2007


This is amazing! Really it's an amazing feature for Office 2007 Word that I can publish a blog from my favorite word editor.


Friday, May 25, 2007

Inaugural Post

Hi , I have just joined in this