添加从类继承到页面的usercontrol [英] Add usercontrol that inherit from class to page

查看:65
本文介绍了添加从类继承到页面的usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个名为baseUc的类,并在我的项目中添加名为myUc的usercontrol。



我的usercontrol是:



  public   partial   class  myUc:baseUc 





i想要在点击按钮时在页面中添加此控件。



i使用此代码:



  public  myUc uc; 





并点击:

 uc =(myUc)LoadControl(〜/ p1 / UserControls / myUc.ascx); 



但我收到此错误:

无法将system.ui.control转换为myUc

出了什么问题?

最好的问候。



我尝试过:



将从类创建的用户控件动态添加到页面。

解决方案

我想你可能是tr从错误的地方加载控件。请参阅 TemplateControl.LoadControl方法(字符串)(System.Web.UI) [ ^ ]。

I create a class with name baseUc and add a usercontrol with name myUc in my project.

my usercontrol is:

public partial class myUc : baseUc 



i want to add this control in a page when i click on a button.

i use this code:

public myUc uc;



and in click:

uc = (myUc)LoadControl("~/p1/UserControls/myUc.ascx");


but i get this error:
can not covert system.ui.control to myUc
what is wrong?
best regards.

What I have tried:

add a user control that created from a class, to a page dynamically.

解决方案

I think you may be trying to load the control from the wrong place. See TemplateControl.LoadControl Method (String) (System.Web.UI)[^].


这篇关于添加从类继承到页面的usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆