MenuTemplate menuTemplate = new MenuTemplate();

menuItem = new MenuItemTemplate("Delete document", "/_layouts/images/delete.gif");
            menuItem.ClientOnClickScript = ""; // What should I put there

On line, menuItem.ClientOnClickScript, what should I put there, so that I can delete document?


You need to call a Javascript (or SharePoint JS-ECMA) function passing "this" as a parameter (plus any other parameters you see fit).

"ConfirmDeleteThenPostBack(this, '%SomeParameter%')";

The function must also exist already loaded, e.g. via a ScriptLink control in the master page, or any other technique available (e.g. script tags).

One example doing exactly that could be seen here http://johanleino.wordpress.com/2009/05/12/solving-using-the-clientonclickusingpostbackevent-in-ascx-usercontrols/ and a full example to build your custom menus on SPGridView is http://blogs.msdn.com/b/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx

  • Ok. I have seen the links. But I need a javascript function for this. Can u write a function for me? – SPBeginer Apr 4 '13 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.