Not sure if this is the best way to do this, but this is what I do. Say you want to auto submit a form on an aspx page. You can call document.formname.submit(); from the body onLoad event and it will submit, but ASP.net will automatically post it back to itself.
First, what I had to do was put on my ASP Classic hat. Look at your <form> and remove the runat=”server”
Then, you can say document.formname.submit(); and it will submit your form.
How do you pass data though?
Well, you have to created input fields, probably hidden like
<input type=”hidden” name=”blah” id=”blah” value=”<%= Request.QueryString[“myvalue”] %>” />
Then you can pass data from another page or whatever and auto submit your form.
It would be nice if you could say in your Page_Load() something like
btnSubmit.Click(); and it would automatically click it and submit your form, but that doesn’t seem to be available at all.
Like I said, there is probably a better way to do this, and it shouldn’t be this complicated, but a few minutes googling for answers left me up in the air. Funny how something that is so easy in ASP Classic turns out to be harder in ASP.NET. ASP.NET wants you to really post back to the same page by default. It hijacks the “action” attribute on the form no matter what with runat=”server on there.