[英]trigger oncommand event from page_load event in asp.net
I am developing site in asp.net and c#.net. 我正在asp.net和c#.net中开发站点。 I have some 2-3 image buttons on my page.
我的页面上有2-3个图像按钮。 I attached comman oncommand event and command argument for all image buttons for some functionality.
我为所有图像按钮附加了comman oncommand事件和命令参数,以实现某些功能。 My code for oncommand is this
我的oncommand代码是这样的
protected void btnMenuTab_Command(object sender, CommandEventArgs e)
{
int CID = Convert.ToInt32(e.CommandArgument);
MethodToCall(CID);
}
This works fine. 这很好。 Now can I call/trigger first image button's click/command event from Page_Load event to call above shown method programmatically.
现在,我可以从Page_Load事件中调用/触发第一个图像按钮的click / command事件,以编程方式调用上面显示的方法。 I want instead of user to click button and get result, I on Page_Load programmatically trigger image button click/command event to show result.
我要代替用户单击按钮并获得结果,而是在Page_Load上以编程方式触发图像按钮单击/命令事件以显示结果。
You can call: 您可以致电:
btnMenuTab_Command(btnMenuTab, new CommandEventArgs("commandName", "argument"));
But you have to specify the integer you're expecting yourself. 但是您必须指定自己期望的整数。
Hey thanks for help but I got solution for it. 嘿,谢谢您的帮助,但我为此找到了解决方案。 Just call command event method as we call other methods but create parameters for it as per our requirement.
就像我们调用其他方法一样,只需调用命令事件方法即可,但可以根据需要为其创建参数。 see I want to call command event so
看到我想调用命令事件
object mysender = (object)ControNameHere;
CommandEventArgs mye = new CommandEventArgs(null, ControNameHere.CommandArgument);
btn_Command(mysender, mye);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.