如何处理aspx页面中的动态用户控件事件
我有一个 aspx 网页,其中动态添加用户控件,如下所示:
UserControl testUsrControl = LoadControl("TestUsrControl") as UserControl;
testUsrControl.ID ="test";
然后我尝试在 aspx 内添加用户控件的事件处理程序,如下所示:
testUsrControl.Drpdatafield_SelectIndexChanged += new EventHandler(this.Drpdatafield_SelectIndexChanged);
但此行在 **testUsrControl.Drpdatafield_SelectIndexChanged ** 处给出错误。错误是“Drpdatafield_SelectIndexChanged
”在 UserControl 中不存在。
如何动态获取aspx页面内testUsrControl的事件。
谢谢, 色法
I have an aspx webpage in which an user control is added dynamically as follows:
UserControl testUsrControl = LoadControl("TestUsrControl") as UserControl;
testUsrControl.ID ="test";
Then I tried adding an event handler of user control inside aspx like below:
testUsrControl.Drpdatafield_SelectIndexChanged += new EventHandler(this.Drpdatafield_SelectIndexChanged);
But this line is giving error at **testUsrControl.Drpdatafield_SelectIndexChanged **. The error is "Drpdatafield_SelectIndexChanged
" doesn't exist in UserControl.
How can get the testUsrControl's events inside aspx page dynamically.
Thanks,
Rupa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将控件转换为正确的类型(例如 MyUserControlType),然后验证它是否正常
您从用户控件标记文件中的 ClassName 获取类型
<% @ Control Language="C#" ClassName="MyUserControlType" %>
You need to cast the control to the correct type (say MyUserControlType) and then verify that it's ok
You get the type from ClassName in the usercontrol markup file
<% @ Control Language="C#" ClassName="MyUserControlType" %>