gpt4 book ai didi

c# - Button.OnCommand += new CommandEventHandler 结果保护级别错误

转载 作者:太空狗 更新时间:2023-10-30 00:42:46 25 4
gpt4 key购买 nike

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

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

}

最佳答案

你应该使用

moreButton.Command += new CommandEventHandler(getMoreInfoCommand_Click);

OnCommand 是一个 protected 方法,而Command 是一个公共(public)事件

关于c# - Button.OnCommand += new CommandEventHandler 结果保护级别错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13768131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com