简体   繁体   English

在ASP.NET中具有验证的多个提交按钮

[英]Multiple submit button with validations in asp.net

In ASP.NET when we have multiple input section with required field validator (Like on header for login with userid & Password is required and second on footer for subscription) when we click on subscription login section's userid required field validator activates and say userid required & i can not submit subscription. 在ASP.NET中,当我们有多个带有必填字段验证器的输入部分时(例如,需要使用用户ID和密码登录的标头为必填项,而用于订阅的页脚则为第二行),当我们单击订阅登录部分的用户ID必填字段验证器并说出用户ID为必填项时,我无法提交订阅。

when i submit subscription details login section should not have concern with this. 当我提交订阅详细信息时,登录部分不应对此有所关注。 how to avoid this conflicts. 如何避免这种冲突。

You have to use the ValidationGroup property for the controls, the validators and the control that submits the postback. 您必须对控件,验证器和提交回发的控件使用ValidationGroup属性。

For each logic group you set the same value of the ValidationGroup property 为每个逻辑组设置相同的ValidationGroup属性值

@Citronas answer is correct, but to add to it, you should also ensure you handle the default behavior correctly when using multiple input forms. @Citronas答案是正确的,但要添加到答案中,还应确保在使用多个输入表单时正确处理默认行为。 Put a panel around each and use DefaultButton to identify the submit control for that panel. 在每个面板周围放置一个面板,并使用DefaultButton标识该面板的提交控件。 This will ensure that if the user presses enter (which is very typical, especially for login forms) the correct submit handler is used. 这将确保如果用户按Enter(这是非常典型的,尤其是对于登录表单),则使用正确的提交处理程序。

Also note that this won't work reliably for all submit control types. 另请注意,这不适用于所有提交控件类型。 See Link Button on the page and set it as default button, work fine in IE but not in Mozila 请参阅页面上的“链接按钮”并将其设置为默认按钮,在IE中可以正常工作,但在Mozila中不能正常工作

A solution is suggested there for this problem, though personally I prefer to address this just by including a hidden button control that uses the same event handler as your visible control, eg 建议为该问题提供解决方案,尽管我个人更喜欢仅通过包含一个隐藏按钮控件来解决此问题,该控件使用与可见控件相同的事件处理程序,例如

<asp:Button runat="server" onclick="Search_Click" ID="SearchButton_Default" style="display:none;" />

Then make this hidden button the default control instead of your LinkButton 然后将此隐藏按钮设置为默认控件,而不是LinkButton

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

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