简体   繁体   English

如何区分过帐表格?

[英]How to distinguish between posted forms?

I'm using Umbraco and every page is a master page which is a sub master of another master basically. 我正在使用Umbraco,每个页面都是一个母版页,基本上是另一个母版的子母版。 Therefore there are multiple PAGE_LOAD calls done per page and I need a way to distingiush between the forms posted. 因此,每页有多个PAGE_LOAD调用,我需要一种在发布的表单之间进行区分的方法。 (So I can run conditionally processing to handle the posted data for each form). (因此,我可以有条件地运行处理以处理每个表单的过帐数据)。

IE I have page.ispostback or whatever, but that will always file I was thinking I could include a hidden field in each form and check for the existance of that to find out which form was posted, how should I do this? IE浏览器我有page.ispostback或其他什么,但那将始终是文件,我一直认为我可以在每个表单中都包含一个隐藏字段,并检查该表单是否存在以找出发布的表单,我该怎么做?

You should consider this to be like any other webforms application. 您应该认为这与任何其他Webforms应用程序一样。

So, don't necessarily try and handle your postbacks in the Page_Load event. 因此,不必尝试在Page_Load事件中处理您的回发。

Let's say you have a Search 'form' and a Subscribe to newsletter 'form'. 假设您有一个搜索“表格”和一个订阅时事通讯“表格”。 The submit button from each will cause the postback of the same page. 每个提交按钮都会导致回发同一页面。 You can attach an event to these buttons to catch the form submittal and handle the functionality of the submittal at this point rather than on Page_Load. 您可以将事件附加到这些按钮上,以捕获表单提交并此时处理提交功能,而不是在Page_Load上。

I usually separate all my mini forms into separate usercontrols with a codebehind which has a btnSubmit_OnClick(object sender, EventArgs e) where I fire all my logic off. 我通常将我的所有迷你表单分成单独的用户控件,并在其btnSubmit_OnClick(object sender, EventArgs e)一个btnSubmit_OnClick(object sender, EventArgs e) ,在其中我将所有逻辑都关闭。

You will also want to ensure that each collection of fields uses a unique ValidationGroup attribute value, so that the submitting of one form doesn't fire the validation of another form. 您还需要确保每个字段集合都使用唯一的ValidationGroup属性值,以便提交一种表单不会触发另一种表单的验证。

The advantage of this is that you can then build up a library of usercontrols for different features which are then all independent of each other. 这样做的好处是,您可以为不同功能建立用户控件库,这些功能彼此独立。 I often find that I can just lift these and reuse them from one Umbraco project to the next. 我经常发现我可以取消这些限制,并将其从一个Umbraco项目中重复使用到下一个项目。

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

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