简体   繁体   English

如何在自定义验证后使用JavaScript提交ASP.NET

[英]How to submit ASP.NET with JavaScript after custom validation

I need to fire some custom JavaScript validation and then submit my ASP.NET using JavaScript. 我需要激活一些自定义JavaScript验证,然后使用JavaScript提交我的ASP.NET。

How do I submit the form using JavaScript? 如何使用JavaScript提交表单?

To do a postback via JavaScript you can call the following server side to create the JavaScript code for you: 要通过JavaScript进行回发,您可以调用以下服务器端为您创建JavaScript代码:

string postBackJavascript = Page.GetPostBackEventReference(yourControl);

This will return the __doPostBack JavaScript code as a string, and you will need place it on your page attached to something or you can call the __doPostBack directly on your own with: 这会将__doPostBack JavaScript代码作为字符串返回,您需要将其放在附加到某些内容的页面上,或者您可以直接使用以下命令调用__doPostBack

__doPostBack(yourControlId,'');

If you're doing it yourself and not using Page.GetPostBackEventReference then make sure to get the ClientID for the control that triggered the validation, like: 如果您自己进行并且不使用Page.GetPostBackEventReference那么请确保获取触发验证的控件的ClientID ,例如:

__doPostBack('<%= yourControl.ClientID %>','');

EDIT: After re-reading your question you didn't say you wanted to trigger the postback based on an ASP.NET control, you might not even be using any ASP.NET controls so in that case if you want to just do a vanilla postback you can do: 编辑:重新阅读你的问题,你没有说你想要基于ASP.NET控件触发回发,你可能甚至没有使用任何ASP.NET控件,所以在这种情况下,如果你想做一个香草回发你可以这样做:

document.forms[0].submit();

If you want to post back, you can use __doPostBack() that ASP.NET put into the <form> . 如果要回发,可以使用ASP.NET放入<form> __doPostBack() Take a look at this link . 看看这个链接 If you want to submit another form just call .submit() on the form element. 如果要提交另一个表单,只需在表单元素上调用.submit()

It should be as simple as 它应该如此简单

document.forms[0].submit(); 

Provided, you only have one form on the page, or else you need to use the form name instead of the index 0. 如果您在页面上只有一个表单,或者您需要使用表单名称而不是索引0。

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

相关问题 触发 Javascript 验证然后 ASP.NET 控制 Submit_Click1 - Trigger Javascript Validation then ASP.NET Control Submit_Click1 如果使用JavaScript在ASP.NET中页面验证失败,如何禁用“提交”按钮 - How to disable the submit button if page validation fails in ASP.NET using javascript 在 javascript function 之后,提交按钮在 asp.net 中未触发 - Submit button not firing in asp.net after javascript function asp.net验证组成功后禁用javascript中的提交按钮 - Disable submit button in javascript after asp.net validationgroup success ASP.Net MVC 3 ViewModel,简洁的JavaScript和自定义验证 - ASP.Net MVC 3 ViewModel, unobtrusive JavaScript and custom validation 如何仅在用户单击提交表单时触发数据验证,而不是在 ASP.NET MVC 中的文本框中更改值后触发数据验证? - How to trigger data validation only when user click on submit form but not after value changing in textbox in ASP.NET MVC? 如何使用javascript在asp.net中手动提交按钮? - How to manually submit a button in asp.net using javascript? 在asp.net项目中,如何提交javascript对象? - In an asp.net project, how can I submit javascript objects? 如何在ASP.NET中禁用JavaScript时处理验证 - How to handle validation when JavaScript is disabled in ASP.NET ASP.NET验证摘要:如何使用JavaScript禁用验证程序? - ASP.NET Validation Summary: How to disable validator with JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM