从 ContentPage 访问 MasterPage 上的 HtmlGenericControl

发布于 2024-08-10 01:10:30 字数 497 浏览 4 评论 0原文

所以我有以下结构;

Start.master (Start.master.cs)

包含方法

DoSomething(string Text)
{
    _MyHtmlControl.InnerText = Text;  
}

和 HtmlGenericControl ID 的_MyHtmlControl

Page.aspx (Page.aspx.cs)

通过 new Start().DoSomething("Test"); 调用方法

这样做会出现以下错误:未将对象引用设置为对象的实例。

我怎样才能让它工作,这样我就可以调用 DoSomething() 并将给定的字符串写入 MasterPage 中定义的 HtmlGenericControl 中?

so I've got the following structures;

Start.master (Start.master.cs)

Contains a Method

DoSomething(string Text)
{
    _MyHtmlControl.InnerText = Text;  
}

And the HtmlGenericControl ID'ed _MyHtmlControl

Page.aspx (Page.aspx.cs)

Calls the Method via new Start().DoSomething("Test");

Doing so gives me the following error: Object reference not set to an instance of an object.

How can I make it work, so I can call DoSomething() and it writes the given string into the HtmlGenericControl that is defined in the MasterPage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

影子的影子 2024-08-17 01:10:30

请参阅:

ASP.Net 母版页:提示、技巧和陷阱

抽象交互

现在是时候拥有母版页了
和内容页面交互。有
我们可以采取不同的方法
实现互动,但最好
方法是使用
母版页的本质:用户
控制。

See:

ASP.Net Master Pages: Tips, Tricks, and Traps

Abstract Interaction

Now it’s time to have the master page
and content page interact. There are
different approaches we can take to
achieve interaction, but the best
approaches are the ones that use the
master page for what it is: a user
control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文