0

I'm trying to debug a ASP.Net site. The code is debugged using Visual Studio 2012 and is running locally using IIS Express on my Windows 10 machine. The web application needs to be run using Internet Explorer 11.

When I run the code, I get an exception that is caught by Visual Studio, in the on-page JavaScript (in a piece of code not shown below). I know for a fact that the code is already out in production and it 100% works. However when I debug the code locally it fails to work as expected.

Here's the code in question:

var elements = document.getElementsByTagName('input');
for(var i = 0; i < elements.length; i++) {
    var value = elements[i].getAttribute('value');
    //....
}

When I run the code locally the elements[i].getAttribute('value') returns null. However when I run this same code in production it works fine. When I debug the code, I can see that the elements[i] has an actual value stored in the "value" attribute, however the above code still returns null.

I'm not allowed to change the code (due to reasons) and since my colleague is able to run the code on his machine using the same setup, I'm inclined to think it's a configuration issue on my machine in either Visual Studio or something else.

I'm open to any suggestions as to what might be the cause.

2 Answers 2

0

I tried to test your above-mentioned code and it is working fine in IE 11 browser.

<!doctype html>
<html>
<head>
</head>
<body>
<input type="text" name="FirstName" value="abc"><br>
<input type="text" name="LastName" value="xyz"><br>
<script>
var elements = document.getElementsByTagName('input');
for(var i = 0; i < elements.length; i++) {
    var value = elements[i].getAttribute('value');
    console.log(value);
}
</script>
</body>
</html>

Output:

enter image description here

It can be a cache related issue. I suggest you clear the cache for that site or hard refresh the page and again try to check the results.

If the issue persists then try to provide more detailed information about the issue. We will again try to check it.

6
  • the code works fine in IE11 when I open the page with IE11 in any other environment it just works. It's when I debug the site using IE 11 using VS 2012 that the code seems to fail. Best I can tell it's has to be down to some configuration setting in Visual Studio 2012 / solution / site Commented Jan 20, 2020 at 14:05
  • Try to clean the solution and again try to rebuild the project and test it. Commented Jan 20, 2020 at 14:11
  • Tried it and to no avail. This is the first time I'm attempting to get the site to work locally on my machine. So it's not a stale build or a cache issue, of that much I'm sure of. Commented Jan 20, 2020 at 14:15
  • Also attempted: switching branches to a known working branch, restarting pc, turning off script debugging, running solution with debugging turned off... Commented Jan 20, 2020 at 14:18
  • It's also failing in Chrome, same issue. I'm starting to think that the issue could be with the ASP.NET development server. However I'm not sure why a web server would be impacting the client side JavaScript, that just doesn't make sense. Commented Jan 20, 2020 at 14:29
0

After a bit more searching and talking to my colleagues I was advised to turn on Enterprise Mode (Tools -> Enterprise Mode) in Internet Explorer.

This, according to this article, renders the page like it would have been rendered in IE8. From what I can tell it also resolves the issue I was seeing.

I hope this can help someone in the future.

Not the answer you're looking for? Browse other questions tagged or ask your own question.