Hi joedirt,
Thank you for posting in the community!
Based on my understanding, you have 2 questions about the form submit.
=================================================
Yes, to submit a form programatically, you must use Form.submit() method.
For your first question, I think you must have some concept
misunderstanding of Asp.net.
In asp.net, there are 2 types of script code: server side(With runat=server
attribute) and client side.
The server side code, it will execute at server side, and you can use C#,
VB, jscript and other languages to write. It is compile execute.
While the client side script will execute at client side, and you only can
use Javascript(or Jscript) and VBscript. It is interpret execute.
To submit a form, normally, you mean submit the entire form from the client
side to the server side, so it is client script. So you can not use C# to
write code.(The client script engine can not recognize the C# code)
For your #2, you can add programmatically add html element data into the
post that is posted back to the server side.(Normal ASP way)
Again, I will clarify the mechanism for you:
Asp.net introduces the concept of Server side web control. The webcontrol
encapsulates some of the behaviors of the html element. All the webcontrol
use the Form.submit() method to postback to the server side. It uses 2
hiden fields: __EVENTTARGET and __EVENTARGUMENT to store the data.
So it makes no sense for you to add the data into these 2 fields, because
at the server side, there are no server side objects to associate with your
data!
But you can programmatically add the data into the form data that is posted
back to the server side. Then at server side, you can use HttpResponse.Form
to access the added data.
Do like this:
At client side:
<INPUT type="button" value="Button" onclick="addformdata()">
<script language="javascript">
function addformdata()
{
var oNewNode = document.createElement("INPUT");
document.Form1.appendChild(oNewNode);
oNewNode.type="text";
oNewNode.name="addeditem";
oNewNode.value="abcdef";
document.Form1.submit();
}
</script>
At server side, you can write the got data into client side:
private void Page_Load(object sender, System.EventArgs e)
{
this.Response.Write(this.Request.Form["addeditem"]);
}
===============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.