1

I found this on a project I'm working on:

 <% If Session("VALUE1") <> "" Then %>
    document.forms[0].action= "<%=Session("VALUE1")%>";
 <% Else %>
    document.forms[0].action="NewPage.aspx"
 <% End If %>

When I single step through this starting at the top line, the code skips over the If Session("VALUE1") but also skips over the Else as well. How is this possible?

1
  • Are you stepping through using Visual Studio, or using the browser javascript debugger? Commented Feb 20, 2015 at 14:35

2 Answers 2

5

Inside both the If and Else blocks, there's no actual server code, only markup (which happens to be javascript). Since there's nothing to execute, your debugger doesn't have anything to stop at. So it's not actually skipping both of them.

If you look at the rendered output, one of the two will end up on the page.

Sign up to request clarification or add additional context in comments.

2 Comments

There is actually server code there, which is actually executed. All the markup outside the server tags are placed in Response.Write statements.
@Guffa Good point - I just published using DLLs for the page contents, and it looks like it's using an HtmlTextWriter to build the whole string first before writing to the response (unless the response is tied into that writer - hard to tell from the decompiled framework code), but same idea. I guess it would be more correct to say what you said, that you just don't "see" the code, so there's nothing for the debugger to stop on.
1

The code isn't skipped, it's just that you don't see the actual code that is executed.

The code that is generated for that markup when the page is compiled looks something like this:

If Session("VALUE1") <> "" Then
  Response.Write("   document.forms[0].action= """)
  Response.Write(Session("VALUE1"))
  Response.Write(""";")
Else
  Response.Write("   document.forms[0].action=""NewPage.aspx""")
End If

As the Response.Write statements are generated and has no corresponding statements in the source code, it will look like they are skipped when you single step through the code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.