4

为什么下面的代码会导致以下错误:

System.Web.UI.WebControls.Button.OnCommand(System.Web.UI.WebControls.CommandEventArgs)' 由于其保护级别而无法访问

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) 
{

}
4

1 回答 1

7

你应该使用

moreButton.Command += new CommandEventHandler(getMoreInfoCommand_Click);

OnCommand是受保护的方法Command而是公共事件

于 2012-12-07T17:37:38.617 回答