添加可重复使用的“盒子”;到我的 ASP.NET Web 应用程序
我正在 Visual Studio 2010 Pro 中使用 C# 在 ASP.NET 4.0 中构建基本的 Web 应用程序。我对 C# 还很陌生,并且已经习惯了 Delphi 编码。我的网站已经有注册/登录功能,虽然我使用了一些 asp.net 控件,但我的大部分页面都是从 SQL 数据库动态加载的,我手动从 C# 编译 HTML 代码并将其插入到文档中。
现在我想做的是实现一个民意调查 - 或投票箱 - 一个可以在不同页面中重复使用的“对象”。我网站的母版页已经有一个永久的左侧面板,其中的内容显示在每个页面上。其中一个是一个小盒子,里面有几个问题的投票。
我需要知道的是如何开始为这样的网页构建独立的插件控件?我不一定指的是单独的 DLL 或任何东西,我现有的 DLL 可以处理所有事情。但我也想在不同的页面中重复使用同一个小投票箱。所以我假设这在某种程度上将被视为一个单独的页面,其尺寸可能约为 120 像素宽 x 80 像素高。每次投票将仅限于登录帐户或 IP 地址(我已经可以访问)。所以这个解决方案必须与现有的asp.net应用程序交互。
那么我如何开始这样一个可以在多个页面中重复使用的插件的“主干”呢?我不打算分发这个插件,我什至不知道这是否是我需要的正确术语。只是一个可以在多个页面上“重复使用”的“盒子”——它必须与 asp.net 应用程序交互。
为了更好地解释我的意思,想象一下 Facebook 如何拥有一个插件,您可以在其中嵌入一些有关喜欢等的一般信息。我想制作我自己的这样的盒子 - 甚至能够将它嵌入到其他网站中。
I'm building a basic web application in ASP.NET 4.0 with C# in Visual Studio 2010 Pro. I'm still very new to C#, and am used to Delphi coding. My website already has registration/login, and although I use some asp.net controls, a majority of my pages are dynamically loaded from my SQL database and I manually compile the HTML code from C# and insert it into the document.
Now what I would like to do is implement a poll - or a vote box - an 'object' which can be re-used in different pages. My website's master page already has a permanent left panel which has things which show on every page. One of these will be a small box with a vote of a few questions.
All I need to know is how do I begin to build an independent plugin control for a web page like this? I don't necessarily mean a separate DLL or anything, my existing one can handle everything. But I'd like to re-use the same little voting box in different pages too. So I'm assuming this will be considered a separate page, in a way, which is probably about 120 pixels wide by 80 high. Each vote will be limited to either login account or ip address (which I already have access to). So this solution must interact with the existing asp.net application.
So how do I begin the 'backbone' of such a plugin which can be re-used in multiple pages? I do not plan on distributing this plugin, and I don't even know if this is the correct term for what I need. Just a 'box' which can be 're-used' on multiple pages - which must interact with the asp.net app.
To better explain what I mean, imagine how Facebook has the plugin where you can embed some general info about likes and such. I'd like to make my own box like this - and even be able to embed it in other websites.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您只需要将民意调查变成用户控件。该文档应该可以帮助您开始使用它们。当涉及到登录信息时,控件可以访问 ASP.NET 页面可以访问的所有内容。不过,它不会处理嵌入其他页面的情况 - 针对您的网站进行身份验证的可嵌入活动内容是一个不小的问题。
正如我在评论中所说,如果您的大部分 HTML 都是作为对 ASP.NET 不透明的 blob 创建的,那么在其中插入用户控件可能会很重要。
It sounds like you just need to make the poll into a user control. The documentation should get you started with them. A control can access everything an ASP.NET page can when it comes to the login information. It won't handle embedding into other pages though – embeddable active content that authenticates against your site is a nontrivial problem.
As I said in the comment, if most of your HTML is creates as a blob that's opaque to ASP.NET, it will probably be nontrivial to insert a user control into the middle of it.