重写受保护的内部方法

发布于 2024-09-10 03:10:01 字数 468 浏览 2 评论 0原文

我正在将一个 Web 应用程序重写为 ASP.Net 4.0,并包含一个菜单控件(自然地绑定到 SiteMap 文件)。虽然我喜欢新的 RenderingMode 属性,但我讨厌它自动在页面底部包含一些 JavaScript 来为菜单添加动画效果。

我更喜欢使用 jQuery 进行更好的控制,但事实证明关闭它非常困难。在一位重量级人物的帮助下,我已经发现 ASP.Net 4.0 菜单控件有一个内部 OnPreRender 方法:

internal void OnPreRender(EventArgs e, bool registerScript);

如何重写此方法以便我可以调用

base.OnPreRender(e, false);

:目前正在尝试,我从 Visual Studio 收到一条错误,指出“方法‘OnPreRender’没有重载需要 2 个参数”。

I'm rewriting a web application to ASP.Net 4.0 and have included a Menu control (bound to a SiteMap file, naturally). While I'm liking the new RenderingMode property, I'm hating the fact that it automagically includes some javascript at the bottom of your page to animate the menu.

My preference would be for greater control using jQuery, but switching that off is proving very difficult. With some help from a very heavy hitter, I've been walked through to the point where I've discovered that the ASP.Net 4.0 Menu control has an internal OnPreRender method:

internal void OnPreRender(EventArgs e, bool registerScript);

How do I override this method so that I can call:

base.OnPreRender(e, false);

When trying at the moment, I'm getting an error from Visual Studio saying that "No overload for method 'OnPreRender' takes 2 arguments".

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

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

发布评论

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

评论(2

彩扇题诗 2024-09-17 03:10:01

您应该能够引用受保护的内部方法,因为它们是受保护内部。如果该方法只是内部,那么您可能会运气不好。

查看 ASP.NET 4 菜单控件,它只有一个 OnPreRender 重写:

protected internal override void OnPreRender(EventArgs e);

因此您应该能够重写它。不确定 OnPreRender(EventArgs e, bool registerScript) 来自哪里(也许它是内部),但事实上基类没有(或者它无法访问)你的问题。

You should be able to refer to protected internal methods as they are protected or internal. If the method is just internal you might be out of luck.

Looking at ASP.NET 4 Menu control, it only has one OnPreRender override:

protected internal override void OnPreRender(EventArgs e);

So you should be able to override it. Not sure where OnPreRender(EventArgs e, bool registerScript) comes from (perhaps it's internal), but the fact that the base class doesn't it(or it's inaccessible) is your problem.

唠甜嗑 2024-09-17 03:10:01

这不是一个直接的答案,但将任何 IHeirarchicalDataSource 的内容(例如站点地图文件)转储到任何数量的 jquery 菜单产品都可以咀嚼并制作的

    中是非常简单的。

Not a direct answer, but its pretty trivial to dump the contents of any IHeirarchicalDataSource, such as a sitemap file, to a <ul> which any number of jquery menu products can chew and make purdy.

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