简体   繁体   中英

ASP.NET POST Problem

I'm new to ASP.NET and have a form tag on an ascx user control. I'm unable to submit the form from javascript because I found out that this form is nested inside a form called 'aspnetForm'. If I just want to make a post to a cgi, how can I accomplish this?

Remove the <form runat='server'> if you don't need it and just use your own form: <form action="page.cgi" method="post"> . You'll not be able to use some server controls. Use their HTML equivalents instead.

If you don't have control on the page, you can use javascript to inject a new form on the page with some hidden fields and set the values upon click of a button.

Something like this:

var myForm = document.createElement("form");
myForm.attributes["action"] = "mycgi.cgi";
myForm.attributes["method"] = "POST";
var myhiddenfield = document.createElement("input");
myhiddenfield.attributes["type"] = "hidden";
myhiddenfield.attributes["name"] = "name"
document.body.appendChild(myForm);
myForm.appendChild(myhiddenfield);

function onFormButtonClick() { // set as onclick on a <button>
    myhiddenfield.value = ... //value read from a textbox or something.
    ...
    myForm.submit();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM