Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  152] [ 7]  / answers: 1 / hits: 28947  / 14 Years ago, tue, july 13, 2010, 12:00:00

I need to fire some custom JavaScript validation and then submit my ASP.NET using JavaScript.



How do I submit the form using JavaScript?


More From » asp.net

 Answers
1

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);


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,'');


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 %>','');


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:



document.forms[0].submit();

[#96243] Sunday, July 11, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myrap

Total Points: 407
Total Questions: 105
Total Answers: 109

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
myrap questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Wed, Jan 15, 20, 00:00, 4 Years ago
Thu, Oct 24, 19, 00:00, 5 Years ago
Thu, Oct 3, 19, 00:00, 5 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;