Why is ASP.NET adding JS to get the Form element?
I am removing the following from my aspx files:
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = ev开发者_运维问答entTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
But when I run the application, it's added back in. How and why is this? How can I permanently remove it?
asp.net uses the _doPostBack
JavaScript code to handle control post back logic, further info can be found in this article - http://aspalliance.com/895_Understanding_the_JavaScript___doPostBack_Function.all
It's Javascript that is automatically generated by ASP.NET to support some of the controls that require certain postback logic, such as asp:LinkButton
and asp:ImageButton
. These aren't standard HTML Form controls, so they require Javascript to trigger a POST when clicked on in the browser.
The script should only actually be generated if ASP.NET thinks you need it, so perhaps you're using a control that does? It shouldn't generate it otherwise. For instance, a plain ASPX page with only a asp:Button
control won't generate the script, but if you add an asp:LinkButton
, it will.
精彩评论