首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebUserControls可以获得项目中其他WebUserControls的类型信息吗?

WebUserControls可以获得项目中其他WebUserControls的类型信息吗?
EN

Stack Overflow用户
提问于 2011-02-08 20:29:35
回答 2查看 132关注 0票数 0

我基本上是在试着让webcontrol互相对话。

我有一个WUC想要从另一个WUC获取信息。

在ControlB的GetDataFromControlA方法中

代码语言:javascript
复制
public List<ControlBData> GetDataFromControlA()
{
    ControlA c = Page.FindControl( IdOfControlA) as ControlA;
    if( c != null)
    {
        return c.Data;
    }
   ...
}

在代码时,ControlB对ControlA...so ControlB一无所知,无法访问其成员,并且上述代码无法编译。

我在想,我必须使用页面中的方法来让控件相互对话……

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-24 17:35:03

我在ControlB.ascx中缺少<%@ Reference Control="~/ControlA.ascx“%>

这“修复”了智能和编译错误!Found here

票数 0
EN

Stack Overflow用户

发布于 2011-02-08 20:43:28

是的,您可以使用方法来实现控件之间的一些通信(因为每个控件最终都属于一个类)。

但是您必须显式地将Control转换为您自己的WUC的Datatype。

示例?

代码语言:javascript
复制
// 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在另一个页面中,只需获取对该页面的引用。

希望这能有所帮助。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4932994

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档