试图从用户控件访问aspx页中的属性时出现错误
本文关键字:属性 错误 用户 控件 aspx 访问 | 更新日期: 2023-09-27 17:53:17
我试图访问一个变量从一个aspx在用户控制如下
MyTestPage testPage = (MyTestPage)this.Parent;
testPage.ID // i am trying to accessing id which exists in the aspx page.
当尝试执行上面的代码时,我得到以下错误
**Unable to cast object of type 'System.Web.UI.WebControls.ContentPlaceHolder' to type 'mynamespace.MyTestPage '.**
我在我的项目中使用母版页。
我可以知道我在哪里搞错了吗?我是开放学习,如果你知道任何更好的技术来访问变量从aspx页面到ascx控制看一看这篇非常好的文章,希望它会对你有所帮助
掌握Page-UserControl通信
和
从用户控件触发页面方法
访问母版页
// Cast the loosely-typed Page.Master
MyTestPage myMasterPage = Page.Master as MyTestPage;
也检查这个
母版页到内容页的交互