我基本上是在试着让webcontrol互相对话。
我有一个WUC想要从另一个WUC获取信息。
在ControlB的GetDataFromControlA方法中
public List<ControlBData> GetDataFromControlA()
{
ControlA c = Page.FindControl( IdOfControlA) as ControlA;
if( c != null)
{
return c.Data;
}
...
}在代码时,ControlB对ControlA...so ControlB一无所知,无法访问其成员,并且上述代码无法编译。
我在想,我必须使用页面中的方法来让控件相互对话……
发布于 2011-02-24 17:35:03
我在ControlB.ascx中缺少<%@ Reference Control="~/ControlA.ascx“%>
这“修复”了智能和编译错误!Found here
发布于 2011-02-08 20:43:28
是的,您可以使用方法来实现控件之间的一些通信(因为每个控件最终都属于一个类)。
但是您必须显式地将Control转换为您自己的WUC的Datatype。
示例?
// Convert it from Control to Button
Button nextBtn = (Button)this.FindControl("ButtonIDHere");
// Make sure it is there (not null)
if (nextBtn != null)
{
// Finally, let your logic does the magic!
nextBtn.OnClientClick = "showPopup();";
// Notice that here you can get the specific control members in addition to its base classes' members
}你不应该在这种情况下使用static,它会让你很头疼。
如果WUC在另一个页面中,只需获取对该页面的引用。
希望这能有所帮助。
https://stackoverflow.com/questions/4932994
复制相似问题