Javascript variable in ASPX page in IF condition.

Marc Davis 1 Reputation point

It's been a while.

But on an ASPX page...if I have a variable that is defined as a global variable hoe can I use that in like the ASPX aspect with like an IF statement.

For example I have a "<script type="text/javascript"> in there I have a "var bitSet = "True"

Then later in the aspx code I have something like

a: (yes, this is VB.NET)

<div class="TestBit" id="TestBit">

<% If (BitSet) Then %>
<h3 class="BitTrue">True</h3>
<% Else %>
<h3 class="BitTrue">False</h3>
<% End If %>


But how do I get the BitSet value from the Javascript in this condition?

A set of technologies in the .NET Framework for building web applications and XML web services.
1,715 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. XuDong Peng-MSFT 6,776 Reputation points Microsoft Vendor

    Hi @Marc Davis ,

    But how do I get the BitSet value from the Javascript in this condition?

    According to your requirement, this cannot be implemented. I think you should learn and try to understand the Page Life-Cycle, so you will understand why this requirement cannot be implemented.

    Because the embed code block is executed before the javascript code. The former (embedded code block) is executed during the page rendering phase, while the latter (javascript code) needs to be executed after the page cycle mentioned earlier, so if you are not pass the variable to server side using postbacks or requests (eg Ajax), you will never get this parameter.

    Hope this can help.

    Best regards,
    Xudong Peng

    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments