如何在自定义验证后使用 JavaScript 提交 ASP.NET
我需要触发一些自定义 JavaScript 验证,然后使用 JavaScript 提交我的 ASP.NET。
如何使用 JavaScript 提交表单?
I need to fire some custom JavaScript validation and then submit my ASP.NET using JavaScript.
How do I submit the form using JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要通过 JavaScript 进行回发,您可以调用以下服务器端来为您创建 JavaScript 代码:
这将以字符串形式返回
__doPostBack
JavaScript 代码,您需要将其放在附加到的页面上或者您可以直接自行调用__doPostBack
:如果您自己执行此操作并且不使用
Page.GetPostBackEventReference
,请确保获取ClientID
对于触发验证的控件,例如:编辑: 重新阅读您的问题后,您并没有说要触发基于 ASP.NET 控件的回发,您可能会甚至不使用任何 ASP.NET 控件,因此在这种情况下,如果您只想进行普通回发,您可以执行以下操作:
To do a postback via JavaScript you can call the following server side to create the JavaScript code for you:
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:If you're doing it yourself and not using
Page.GetPostBackEventReference
then make sure to get theClientID
for the control that triggered the validation, like: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 放入
If you want to post back, you can use
__doPostBack()
that ASP.NET put into the<form>
. Take a look at this link. If you want to submit another form just call.submit()
on the form element.它应该像简单的那样
,前提是,页面上只有一个表单,否则您需要使用表单名称而不是索引 0。
It should be as simple as
Provided, you only have one form on the page, or else you need to use the form name instead of the index 0.