1

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

1 Answer 1

2

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!.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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