母版页、表单页、表单 runat=server >母版页上的所有 onclick 方法?

发布于 2024-09-02 18:10:23 字数 882 浏览 4 评论 0原文

我遇到的问题是我有多个嵌套母版页:

  • 级别 1:全局(页眉、页脚、登录、导航等...)
  • 级别 2:特定(搜索页面,帐户页面等...)
  • 3级:现在页面本身

,因为只有一个表单可以有runat=server,我将表单放在全局页面(这样我就可以处理登录、反馈等事情......)。

现在有了这个解决方案,我还必须将例如第 3 级(见上文)方法,例如搜索也放在第 1 级母版页上,但这将导致该页面包含来自所有代码的繁重(用于开发)地方,甚至那些仅在单个页面上使用的地方(例如更改电子邮件表单)。

有没有办法将 onclick 事件(例如:ChangeEMail)中的此类方法从级别 1(全局母版页)委托到级别 3(单个页面本身)。

更清楚地说: 我不想在全局母版页代码上使用 ChangeEMail 方法,但希望以某种方式将其“移动”到实际使用它的唯一页面。目前它必须位于全局主控上的原因是全局主控具有 form runat=server 并且每个 aspx 页面只能有其中一个。

这样,构建代码会更容易(更符合逻辑)。

thnx(希望我解释正确)

已经搜索过,但没有找到任何有关处理这种情况的一般信息,通常答案是:母版页上有所有方法,但我不喜欢它。所以任何将其移动到特定页面的方法都会很棒。 thnx

编辑也是同一件事的一部分...... 另一方面 - 如何从母版页访问内容页上的 textbox1.text ?有什么最佳实践吗?

the problem i have is that i have multiple nested master pages:

  • level 1: global (header, footer, login, navigation, etc...)
  • level 2: specific (search pages, account pages, etc...)
  • level 3: the page itself

now, since only one form can have runat=server, i put the form at global page (so i can handle things like login, feedback, etc...).

now with this solution i'd have to also put the for example level 3 (see above) methods, such as search also on the level 1 master page, but this will lead to this page being heavy (for development) with code from all places, even those that are used on a single page only (change email form for example).

is there any way to delegate such methods from the onclick events (for example: ChangeEMail) from level 1 (global masterpage) to level 3 (the single page itself).

to be even more clear:
i want to NOT have to have the method ChangeEMail on the global master page code behind, but would like to 'MOVE' it somehow to the only page that will actually use it. the reason why it currently has to be on the global master is that global master has form runat=server and there can be only one of those per aspx page.

this way it will be easier (more logical) to structure the code.

thnx (hope i explained it correctly)

have searched but did not find any general info on handling this case, usualy the answer is: have all the methods on the master page, but i don't like it. so ANY way of moving it to the specific page would be awesome. thnx

edit also part of the same thing...
on the other hand - how to access the textbox1.text for example on the content page from master page? any best practice for this?

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

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

发布评论

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

评论(1

雨的味道风的声音 2024-09-09 18:10:23

如果将“搜索”按钮和文本框放在 .aspx 本身(级别 3)上,事件处理程序也将进入页面(或其隐藏代码)。表单标签位于全局母版页(级别 1)上并不重要

至于你的第二个问题:你可以使用

var tb = this.FindControl("textbox1") as TextBox;

If you put the Search button and textbox on the .aspx itself (level 3) the event handler will also go in the page (or its codebehind). It doesn't matter that the form tag is on the global masterpage (level 1)

As for your second question: You can use

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