Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can I add my method instead of URL of a website, I can see another option as "ClientOnClickScript" but not sure how exactly I can do it tho, here's my code

public class MyUserControl: WebControl
{
    private MenuItemTemplate _action;

    protected override void CreateChildControls()
    {
       _action = new MenuItemTemplate
       {
         Text = "hahahahaha",
         Description = "whatever",
         ImageUrl = "/_layouts/images/abc.gif",
         ClientOnClickNavigateUrl = "http://www.freehostingmarket.co.uk"
       };

       Controls.Add(_action);
    }

    private void myMethod(string linkToURL, string documentLibraryName)
    {
       //mYcode
    }
}

I got these 4 options I think but not sure which one will work,

  • ClientOnClickNavigateUrl
  • ClientOnClickPostBackConfirmation
  • ClientOnClickScript
  • ClientOnClickUsingPostBackEvent
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

To handle click event of MenuItemTemplate.
1. Subclass MenuItemTemplate, IPostBackEventHandler and declare an event inside the class to which you can subscribe.
2. Instantiate this class instead of MenuItemTemplate and handle the event. That's it.

Browse this excellent article Handling a PostBack for more details. Good Luck!.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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