在usercontrol构造函数中传递参数 [英] passing arguments in usercontrol constructor

查看:107
本文介绍了在usercontrol构造函数中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将true参数传递给用户控件构造函数吗?



Main.cs

I need to pass the "true" argument to user control constructor?

Main.cs

UserControl uc = (UserControl)Page.LoadControl(typeof(CallLogControl), new object[] { true }); 



错误:调用目标引发了异常。

我收到此错误,如何解决?



USerControl.ascx.cs:


Error: Exception has been thrown by the target of an invocation.
I''m getting this error, how to resolve it?

USerControl.ascx.cs:

public CallLogControl(bool isCurrentCall)
{

}

推荐答案

您永远不会自己实例化用户控件。页面框架为您做到了这一点。因此,如果您在施工期间必须将某些属性设置为true,则流程为:



1.拥有 IsCurrentCall <等公共财产/ code>

2.在必须添加控件的aspx标记中执行以下操作:

You will never be instantiating a user control by yourself. The page framework does that for you. So if you must have some property set as true during the construction, the process would be:

1. Have a public property like IsCurrentCall
2. In the aspx markup where you must have added the control do this:
<uc1:CallLogControlID="CallLogControl1" runat="server" IsCurrentCall="true"></uc1:CallLogControl>





这样这个p在创建控件时将设置roperty。



This way this property will be set when your control is getting created.


这篇关于在usercontrol构造函数中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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