MenuItemTemplate.ClientOnClickScript property

Sets or retrieves the client-side Ecma script to execute when the menu entry is clicked.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public string ClientOnClickScript { get; set; }

Property value

Type: System.String
A String that represents the script.

If the ClientOnClickScript property is set after the ClientOnClickNavigateUrl property, ClientOnClickNavigateUrl is reset to a null reference (Nothing in Visual Basic).

The values for the ClientOnClickScript property may contain tokens for client-side replacement, enclosed in percent sign (%) characters.

This example shows how to include dynamically replaced tokens in a call to an Ecma script function. Note that the token values must be properly encoded for use as URL parameters in a quoted Ecma script string literal value.

MenuTemplate customerMenu = new MenuTemplate();

MenuItemTemplate editCustomer = 
  new MenuItemTemplate("Edit", "/images/edit.gif");
editCustomer.ClientOnClickNavigateUrl = 
  "/EditCustomer.aspx?Id='%CustomerId%'";
customerMenu.Add(editCustomer);

MenuItemTemplate deleteCustomer = 
  new MenuItemTemplate("Delete", "/images/delete.gif");
deleteCustomer.ClientOnClickScript = 
  "ConfirmDeleteThenPostBack(this, '%CustomerId%', '%CustomerName%')";
customerMenu.Add(deleteCustomer);

MenuItemTemplate displayInvoices = 
  new MenuItemTemplate("Display Invoices", "/images/invoice.gif");
displayInvoices.SetClientOnClickUsingPostBackEvent(InvoiceDetailControl, 
  "CustomerId=%CustomerId%");
customerMenu.Add(displayInvoices);

...

foreach(Customer customer in CustomersResults)
{
    TableCell cell = new TableCell();
    row.Add(cell);

    Menu menu = new Menu();
    menu.TokenValues.Add("CustomerId", customer.Id.ToString());
    menu.TokenValues.Add("CustomerName", customer.Name);
    cell.Add(menu);
}
Dim customerMenu As New MenuTemplate()

Dim editCustomer As New MenuItemTemplate("Edit", "/images/edit.gif")
editCustomer.ClientOnClickNavigateUrl = "/EditCustomer.aspx?Id='%CustomerId%'"
customerMenu.Add(editCustomer)

Dim deleteCustomer As New MenuItemTemplate("Delete", "/images/delete.gif")
deleteCustomer.ClientOnClickScript = "ConfirmDeleteThenPostBack(this, '%CustomerId%', '%CustomerName%')"
customerMenu.Add(deleteCustomer)

Dim displayInvoices As New MenuItemTemplate("Display Invoices", "/images/invoice.gif")
displayInvoices.SetClientOnClickUsingPostBackEvent(InvoiceDetailControl, "CustomerId=%CustomerId%")
customerMenu.Add(displayInvoices)

...

For Each customer As Customer In CustomersResults
    Dim cell As New TableCell()
    row.Add(cell)

    Dim menu As New Menu()
    menu.TokenValues.Add("CustomerId", customer.Id.ToString())
    menu.TokenValues.Add("CustomerName", customer.Name)
    cell.Add(menu)
Next customer

This example shows how to declare a menu by using ASPX markup.

<SharePoint:MenuTemplate runat="server" id="CustomerMenu">
<SharePoint:MenuItemTemplate id="CustomerMenu_Edit" runat="server" Text="Edit"
ClientOnClickNavigateUrl="/EditCustomer.aspx?Id='%CustomerId%" />
ImageUrl="/images/edit.gif" />
<SharePoint:MenuItemTemplate id="CustomerMenu_Delete" runat="server" Text="Delete"
ClientOnClickScript="ConfirmDeleteThenPostBack(this, '%CustomerId%', '%CustomerName%')"
ImageUrl="/images/delete.gif" />
</SharePoint:MenuTemplate>               
Show: