ASP.Net 页面抽象

发布于 2024-08-17 04:59:51 字数 423 浏览 7 评论 0原文

我们有一个 win 应用程序,可以在 Web 浏览器中显示 Web 表单。 为了从此 Web 表单获取数据,我们使用隐藏文本框并使用 Web 浏览器控件的 HtmlDocument 对象获取其文本。 我想对这个具有此文本框元素的 Web 表单进行抽象,以便其他表单可以使用此抽象。 我制作了一个 Web 控件并将文本框放在上面。我认为如果我将此控件放在我的页面上,它将具有文本框。当我运行我的应用程序时,我注意到文本框已呈现,但有其控件名称在其名称 (WebControl$TextBoxName) 及其 id(WebControl_TextBoxName) 中,并且 win 应用程序会抛出异常,因为它无法通过其 id(TextBoxName) 找到该元素。 所以这是我的问题: 如何制作一个带有一些元素的抽象 Web 表单/Web 控件,并且我可以使用它来使我的最终表单具有这些元素? (他们的名字和ID不应更改) 感谢您的帮助

We have a win application that shows a web form in a web browser.
In order to get data from this web form we are using a hidden text box and get its text using HtmlDocument object of web browser control.
I want to make an abstraction of this web form that has this text box element so that other forms can use this abstraction.
I made a web control and put the text box on it.I thought that if I put this control on my page it would have the text box.When i ran my application I noticed that the text box had been rendered but had its control name in its name (WebControl$TextBoxName) and its id(WebControl_TextBoxName) and the win app throw an exception since it couldn't find the element by its id(TextBoxName).
So here's my question:
How can I make an abstract web form/web control that has some elements on it and I can use it to make my final forms have these elements on them? (their names and ids should not be changed)
Thank you for your help

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

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

发布评论

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

评论(2

空城旧梦 2024-08-24 04:59:52

dotNet 4.0 支持静态 ID,因此它们不会被破坏,请阅读 Client Id Mode

或者,您可以覆盖控件的呈现,以输出具有您想要的任何 ID 的标准 html 隐藏表单字段,然后还添加一个自定义属性,该属性将返回文本框,该文本框将隐藏它不是 asp.net 服务器控件的事实。

dotNet 4.0 supports static id's so they don't get mangled, read up on Client Id Mode

Alternatively, you could override the render of your control to output a standard html hidden form field with whatever ID you want, and then also add a custom property that will return the textbox that will hide the fact that it isn't an asp.net server control.

薄荷梦 2024-08-24 04:59:52

虽然我从未使用过 WinForms 中的浏览器控件,但我认为您想要使用的是母版页。假设您在浏览器控件中呈现的是一个 ASPX 页面,请创建一个包含您想要从中获取数据的隐藏文本框的母版页,并告诉您想要拥有该通用控件的所有页面使用您的母版页。当页面呈现时,控件 ID 将为“ctl00_TextBoxName”。无法绕过 ID 连接,因为需要唯一的 ID,并且这是保证 ASP.NET 的所有嵌套控制功能的唯一性的唯一方法。但是,这样做将保证您在创建的继承母版页的每个新表单上始终具有相同名称的控件。希望有帮助!

总之(因为谁读段落?):

  • 创建母版页
  • 将公共控件放在母版页中
  • 让您的表单继承母版页

您可以在 MSDN 文档

Though I've never used the browser control in WinForms, I think what you want to use is a Master Page. Assuming what you're rendering in the browser control is an ASPX page, create a Master Page with the hidden text box that you want to grab your data from, and tell all of the pages you want to have that common control on to use your Master Page. When the page renders, the control id will then be "ctl00_TextBoxName". There is no way of getting around the ID concatenation, since unique IDs are needed and that's the only way to guarantee uniqueness with all the nested control abilities of ASP.NET. However, doing this will guarantee you always have that control named the same on every new form you create that inherits the Master Page. Hope that helps!

In summary (because who reads paragraphs?):

  • Create Master Page
  • Place your common control in the Master Page
  • Have your Form inherit the Master Page

You can read up on how Master Pages work in MSDN's Documentation.

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