如何自定义验证后,用JavaScript提交ASP.NET [英] How to submit ASP.NET with JavaScript after custom validation
问题描述
我要火一些定制JavaScript验证,然后使用JavaScript提交我的ASP.NET。
I need to fire some custom JavaScript validation and then submit my ASP.NET using JavaScript.
我如何提交使用JavaScript的形式?
How do I submit the form using JavaScript?
推荐答案
要做到回发通过JavaScript你可以调用以下服务器端创建JavaScript的code你:
To do a postback via JavaScript you can call the following server side to create the JavaScript code for you:
string postBackJavascript = Page.GetPostBackEventReference(yourControl);
这将返回 __ doPostBack
JavaScript的code作为一个字符串,你需要将其放置在页面上附加的东西,或者你可以拨打 __ doPostBack
直接在自己的搭配:
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(yourControlId,'');
如果你正在做自己,而不是使用 Page.GetPostBackEventReference
然后确保获得客户端ID
的触发验证,控制,如:
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:
__doPostBack('<%= yourControl.ClientID %>','');
编辑:重新阅读你的问题后,你没有说你想基于ASP.NET控件来触发回发,你可能甚至不使用任何ASP.NET控件所以在如果你想只是做了回发香草你可以做到这一点的情况下:
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:
document.forms[0].submit();
这篇关于如何自定义验证后,用JavaScript提交ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!