为什么我的ASP.NET页面注入这个WebResource.axd的JavaScript文件? [英] Why is my ASP.NET page injecting this WebResource.axd Javascript file?

查看:161
本文介绍了为什么我的ASP.NET页面注入这个WebResource.axd的JavaScript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在我的ASP.NET页面上查看源代码,我得到下面的代码片段:

When I view source on my ASP.NET page I get the following snippet:

<script type="text/javascript"> 
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script> 

<script src="/WebResource.axd?d=5lheyan7fritNTjDRpG8vA2&amp;t=633734967316503584" type="text/javascript"></script>

在.aspx文件看起来有点像这样:

the .aspx file looks kinda like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="NaturalDateDemo._Default" %>

<form id="form1" runat="server" enableviewstate="False">
   Enter something to parse:<br />
   <asp:TextBox ID="TextBox1" runat="server" Width="270px"></asp:TextBox>
   <asp:Button ID="Button1" runat="server" Text="Parse" PostBackUrl="Default.aspx" CausesValidation="False" EnableViewState="False" UseSubmitBehavior="true" />
</form>

这两个code的块(字面code和东西在 /WebResource.axd )似乎与做的 JavaScript的基于后背上,我想不出任何理由,我的网页需要的的JavaScript 以做后背上。

Both of the chunks of code (the literal code and the stuff in /WebResource.axd) seem to be related to doing JavaScript based post-backs and I can't think of any reason that my page would require JavaScript to do the post-backs.


  • 这是什么做的?

  • 这是哪里来的?

  • 可以的我摆脱它?

  • 如何的我可以摆脱它?

  • What is this doing?
  • Where is it coming from?
  • Can I get rid of it?
  • How can I get rid of it?

这个问题是来自来的页


一个小谷歌工作中发现表明的验证控件将导致这一点,但我不认为我有任何验证控件。

A little Google work found this indicating that validation controls would cause this, but I don't think I have any validation controls.

综观详细 WebResource.axd的文件显示了很多的东西看起来是,我无法找到任何地方,以任何引用锅炉板的功能。

Looking at the WebResource.axd file in detail shows a lot of what looks to be boiler plate function that I can't find any references to from anywhere.


经过进一步调查,似乎我的提交按钮是不是做什么我还以为是因为它有一些JavaScript在的onclick 处理程序。不过使用Firebug我可以看到该页面正在做一个完全刷新(HTTP响应有整页文本),所以我不知道那是什么的。 OTOH我现在看到的是不应该存在(因为没有验证)的 __ EVENTVALIDATION 参数,所以这可能是有趣的抬头。

After further investigation it seem that my submit button is not be doing what I thought it was because it has some JavaScript in its onclick handler. However using FireBug I can see that the page is doing a full refresh (the HTTP response has the full page text) so I have no clue what that's about. OTOH I'm now seeing an __EVENTVALIDATION argument that shouldn't be there (because there is nothing to validate) so that might be interesting to look up.


这似乎基于下面的回答者什么我遇到的是默认的(唯一?)的方式对ASP.NET做了后回是通过JavaScript即使一个基本的HTML表单会做就好了。 (我个人认为这是一个愚蠢的设计选择在MS一部分; ASP.NET不应该引入JavaScript的依赖,直到你要求它做一些事情,不能没有它做。)

It seems based on the answerer below that what I'm running into is that the default (only?) way for ASP.NET to do a post-back is via JavaScript even when a basic HTML Form would do just fine. (Personally I think this is a stupid design choice on MS part; ASP.NET shouldn't introduce the JavaScript dependency until you ask it to do something that can't be done without it.)

根据该意见,几个人纷纷猜测,我不知道我在说什么。 (我就满足,我使用后回到一词混淆由错过这个问题,认为它只是意味着基于JS的东西)。虽然我不知道ASP.NET的实现细节,我不知道如何普通HTTP POST东西的作品和我认为是基于考虑我将如何实施该解决方案我自己,而不是仅仅根据我怎么想它的工作。

Based on that opinion, several people have speculated that I don't know what I'm talking about. (I will grant that I confused the issue by miss using the term "post-back", thinking it only implies JS based stuff.) While I don't know the implementation details of ASP.NET, I do known how the general HTTP POST stuff works and my opinion is based on considering how I would implement the solution my self and not just based on how I would like it to work.

推荐答案

答案是比我在这里看到简单得多:只是删除一项PostBackUrl 按钮和所有的JavaScript消失就像魔术。

The answer is a lot simpler than any I've seen here: just remove the PostBackUrl from the Button and all JavaScript disappears like magic.

没有JavaScript,一个HTML按钮无法提交到另一页比&LT指定的页面;形式的行动=...&GT; 。但是,ASP.NET确实提供了一个可能性,如果指定了一项PostBackUrl 来做到这一点外的开箱上按钮。这就是JavaScript的大概是:支持非默认后回来。

Without JavaScript, an HTML button cannot submit to another page than the page specified in <form action="...">. However, ASP.NET does provide a possibility to do this out-of-the-box if you specify a PostBackUrl on a Button. That's what the JavaScript is about: supporting a non-default post-back.

在这种特定的情况下,你的一项PostBackUrl 是一样的&LT;形式&GT;的 动作,但显然ASP.NET做到这一点任何非空字符串触发此包装脚本不是特殊情况。

In this specific case your PostBackUrl is the same as the <form>'s action, but apparently ASP.NET does not special-case this and any non-empty string triggers this wrapper script.

这篇关于为什么我的ASP.NET页面注入这个WebResource.axd的JavaScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆