T0:bryanscn 学长。
小弟现在遇到一个问题跟你在04年时的一个提问类似。。不知道你当时是怎么解决的?我现在急想知道这个答案。。
不知道能否得到你的提示。。谢谢了。
我的QQ:277648148问题如下:如何将外部参数传入ascx控件内?
我自己做了个控件add.ascx
在page里这样使用:
System.Web.UI.UserControl _innerControl;
...
{
....
int a = 3;
_innerControl.LoadControl("/bin/add.ascx");
....
}
现在我想把参数a的值输入控件add.ascx中,其中add.ascx的代码是写在page前台的,即写<script language=c# runat=server>... ...</script>的
请问应该怎么传进去呢?
我试过Session ,ViewState, Application好像都不行,加?par=3也不行
清大虾指教!!
ps:我这么做是为了在sps 2007中的web part能够引用这个控件,也就是把web part的参数传入其中。
如果有哪位朋友知道这个解答的。可否也帮小弟下。。谢谢。。
小弟现在遇到一个问题跟你在04年时的一个提问类似。。不知道你当时是怎么解决的?我现在急想知道这个答案。。
不知道能否得到你的提示。。谢谢了。
我的QQ:277648148问题如下:如何将外部参数传入ascx控件内?
我自己做了个控件add.ascx
在page里这样使用:
System.Web.UI.UserControl _innerControl;
...
{
....
int a = 3;
_innerControl.LoadControl("/bin/add.ascx");
....
}
现在我想把参数a的值输入控件add.ascx中,其中add.ascx的代码是写在page前台的,即写<script language=c# runat=server>... ...</script>的
请问应该怎么传进去呢?
我试过Session ,ViewState, Application好像都不行,加?par=3也不行
清大虾指教!!
ps:我这么做是为了在sps 2007中的web part能够引用这个控件,也就是把web part的参数传入其中。
如果有哪位朋友知道这个解答的。可否也帮小弟下。。谢谢。。
在MOSS 2007中。get{}set{} 只能写在webpart中才能在属性栏中才能显示出来。但我现在想要在ascx中得到这个值。。所以不知道要怎么作到。。
再次发现自己的理解能力如此之低2。
在你的 ascx 中定义一个属性// add.ascx
<script language=c# runat=server>
public int MyPropertyA
{
get {
object o = ViewState["MyPropertyA"];
return (o == null) ? 0 : (int)o;
}
set { ViewState["MyPropertyA"] = value; }
}
</script>// 使用
int a = 3;
MyUserControl uc = _innerControl.LoadControl("/bin/add.ascx") as MyUserControl; // 假设你的 用户控件名为 MyUserControl
uc.MyPropertyA = 3;
Response.Write(uc.MyPropertyA);
[email protected]
[email protected]
我现在有两个文件.一个是STMenuBlock.cs (webpart文件).在这里面有这么一句代码
Control _innerUserControl = new Control();
_innerUserControl = this.Page.LoadControl("/bin/STMenuBlock.ascx");
this.Controls.Add(_innerUserControl);假设在这个.cs文件中.要传这么一个值给STMenuBlock.ascx,要怎么传.(用户控件是接收方)
(this.FindControl(控件id) as 控件类).公有属性 应该就可以传值了