简体   繁体   English

将服务器控件添加到没有表单的页面

[英]Add server controls to a page that have no form

I have A single page that has the following structure 我有一个页面具有以下结构

<form runat="server"><placeholder></placeholder></form>

I have a control call 'feed' that gets added to the placeholder. 我有一个控制调用'feed',它被添加到占位符中。 The control that gets added, holds multiple other controls called 'product'. 添加的控件包含多个名为“product”的其他控件。

I load the products into the feed dynamically with ajax. 我用ajax动态地将产品加载到feed中。

The problem is, that the mark-up in the product control contains server side buttons that require a form tag with runat=server. 问题是,产品控件中的标记包含需要带有runat = server的表单标记的服务器端按钮。 Otherwise the page wont compile. 否则页面不会编译。

The page compiles fine once I add the necessary form tags to the 'product' control. 一旦我将必要的表单标签添加到“产品”控件,页面就会编译好。 This is not satisfactory as I don't want multiple form tags on the page at once. 这并不令人满意,因为我不想在页面上同时使用多个表单标签。

Is there any way around this? 有没有办法解决?

You can either add a single <form runat=server> that wraps all server controls or don't use server controls (normal html tags). 您可以添加一个包装所有服务器控件的<form runat=server> ,也可以不使用服务器控件(普通的html标记)。

Or, use a more flexible framework like MVC that gives you full control of your markup. 或者,使用更灵活的框架(如MVC),可以完全控制标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM