Why is my ASP.NET page injecting this WebResource.axd Javascript file?

前端 未结 5 1963
栀梦
栀梦 2021-01-01 02:45

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



        
相关标签:
5条回答
  • 2021-01-01 02:51

    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.

    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.

    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.

    0 讨论(0)
  • 2021-01-01 02:52

    If you are using a control that inherits another class, the type passed must be the type of the parent, not the base class

    0 讨论(0)
  • 2021-01-01 03:01

    4 things to check:

    1. Are you using an UpdatePanel somewhere on the page?
    2. Do you have any javascript making calls to web methods in your code behind?
    3. Does your master page have anything in it that might be adding to your output?
    4. Are you referencing any controls from an external library?

    Once you've investigated that, you might be able to at least cut out some options as to the source of the problem.

    Can you provide any sample of the code on your ASPX?

    EDIT: Your post now includes a link to the source page. The page has a postback button on the form, which renders results of parsing without doing a full postback (notice that the whole screen doesn't reload). The webresource URL in your path contains the javascript functions used to accomplish this. Your code is doing a partial postback, which is why you have postback-related code on your page.

    EDIT #2: To completely remove postbacks from the system, you will need to remove the .NET form submission currently being used by your application. Your button is posting back, therefore it needs code to perform this postback to your server. If you want to remove this, you need to do things with old-school HTML posting straight to another URL. You will need a standard POST form with an action URL and form input fields. However, at that point, you are sort of defeating the purpose of using .NET and its postback support. I guess the final question is why do you need to remove this javascript?

    0 讨论(0)
  • 2021-01-01 03:12

    This is how .NET postbacks work, and why a lot of people are moving the the .NET MVC model. In order for the postbacks to work correctly, .NET actually relies on javascript to do a lot of the dirty work. The only way you can really get rid of it is to go with the MVC model.

    0 讨论(0)
  • 2021-01-01 03:12

    From looking at your page, I don't understand how you "can't think of any reason that [your] page would require post-backs." It's quite clear to me that when clicking on your Parse button you are calling some methods on the server to interpret the passed in value and convert it to a date, then returning that date to the browser so that the user can see it.

    Am I right in assuming that you did not originally create this page and have little experience with ASP.Net? It's not that "MS screwed up big time" (as you mentioned in your comment on Jay S's very well done answer that probably deserves a check mark) it's that your requirements seem to have changed and now you need to ensure that the page works when JavaScript is disabled, which is possible to do with ASP.Net, it's just not the natural way for ASP.Net to do things. However, this will likely require a pretty hefty overhaul of the page, as most drastic changes to requirements do.

    0 讨论(0)
提交回复
热议问题