6

I have an implementation that uses Sheer UI and I'm creating a combobox on a page which on changes will perform a certain action. On the implementation of the Change method should it be registered as a command? Or is the method declaration on the MyClass is not correct?

My Xml combobox looks like this:

 <Combobox ID="Target" Width="100%" Change="OnSortChanged">
                  <ListItem Value="Alphabetical" Header="Alphabetical"/>
                  <ListItem Value="Created" Header="Date Created"/>
                  <ListItem Value="Updated" Header="Date Modified"/>
                </Combobox>

The code beside has a method declared as:

 protected void OnSortChanged(Combobox sender, EventArgs args)
 {                
     //Do stuff
 }

When I change the dropdown value on the interface I get the exception:

Exception: System.Exception Message: Method "OnSortChanged" not found in MyNamespace.Web.XmlControls.MyClass. (method: Sitecore.Web.UI.Sheer.ClientPage.Dispatch(String command)). Source: Sitecore.Web.UI.Sheer.ClientPage.Dispatch(String command) at Sitecore.Diagnostics.Error.Raise(String error, String method) at Sitecore.Shell.Framework.Commands.CommandManager.GetMethodCommand(String command) at Sitecore.Web.UI.Sheer.ClientPage.Dispatch(String command) at Sitecore.Web.UI.Sheer.ClientPage.RaiseEvent() at Sitecore.Web.UI.Sheer.ClientPage.OnPreRender(EventArgs e) at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

  • Instead of Combobox for the sender, if you use the object one, does it works? – Hishaam Namooya Jun 22 '17 at 15:49
  • nope. same thing – Diego Jun 22 '17 at 15:59
  • two questions: 1. are any other methods of the codebehind being called? 2. could you post the full Xml for the control? Shot in the dark: try making OnSortChanged public? – Ben Lipson Jun 22 '17 at 16:38
6

You need to remove the parameters from the method declaration. It should be

protected void OnSortChange()

You should then be able to access the sender by the ID used on the form.

You many need to define the control in the codebehind if you have not already:

protected Sitecore.Web.UI.HtmlControls.Combobox Target
| improve this answer | |
2

The issue is with the method declaration. You need to change it to the one below:

protected void OnSortChanged()
{       
    //Retrieve the selected value
    var targetValue = this.Target.SelectedItem.Value         

    //Do stuff
}

All the different actions do not take any parameters. Even if it is a Click, DblClick. They will not take any parameters in the method. The main reason is because you already defined the Type of the ID in the code-beside.

| improve this answer | |

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.