Why does below code result in the following error:
System.Web.UI.WebControls.Button.OnCommand(System.Web.UI.WebControls.CommandEventArgs)’ is inaccessible due to its protection level
protected void btnSearch_Click(object sender, EventArgs e)
{
...
UpdatePanel updatePanel;
...
Button moreButton = new Button();
moreButton.ID = "moreButton";
moreButton.Text = "More";
updatePanel.ContentTemplateContainer.Controls.Add(moreButton);
moreButton.CommandName = "More";
moreButton.CommandArgument = department.ID + "|department";
moreButton.OnCommand += new CommandEventHandler(getMoreInfoCommand_Click);
...
updatePanelList.Add(updatePanel);
}
protected void getMoreInfoCommand_Click(Object sender, CommandEventArgs e)
{
}
You should use
OnCommandis a protected method, whileCommandis a public event.