gpt4 book ai didi

ASP.NET 用户控件继承用户控件生成空引用

转载 作者:行者123 更新时间:2023-12-02 17:03:04 24 4
gpt4 key购买 nike

这一定是一个常见问题。

  • 用户控件 A 有一个文本框 T。
  • 用户控件 B 继承自用户控件 A。
  • 用户控件 B 被放置到页面 P 上。

在页面 P 的 Page_Load 事件期间,如果您尝试访问 TextBox T,您会发现它为空。

有没有一个优雅的解决方案?

最佳答案

从 UserControls 继承 UserControls 并不是一个好的策略。父 UserControl 中的元素将不会被渲染 - 这就是您的 TextBox 为 null 的原因。

更好的选择是将 UserControl A 包含在 UserControl B 中 - 这样 UserControl A 的元素就可以在其他 UserControl 中重复使用。

看看关于继承 UserControls 的另一篇文章 - How (if at all) can you make an ASP.NET UserControl inherit from another UserControl? .

关于ASP.NET 用户控件继承用户控件生成空引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4273018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com