1

I am new to asp.net and I need a little help.

The problem I need to set the visibility of a button based on whether or not "newflag" appears in the url. For example http://localhost:38805/result.asp?newflag

I have to use asp.net and javascript

Here is my current asp.net and JS code

asp.net

newflag = Request.Form("newflag")

    If newflag = false Then
        newflag = "null"
        Else
        newflag = "true"
        End If

JS

var newflags = '<%= newflag %>';
        console.log(newflags);
        if (newflags === "null" ) {
            document.getElementById('newflag').style.visibility = "hidden";

        }
else if(newflags === "true" ){

    document.getElementById('newflag').style.visibility = "visable";
}

Currently I am getting false from the console even with adding it to the url string.

Top-Bot
  • 782
  • 1
  • 6
  • 21

1 Answers1

1

Instead of leveraging ASP.NET to get the query string parameter and set it to a variable to be later read by Javascript, why not just use Javascript?

See this answer for a detailed list of how to read query string parameters in pure Javascript

Community
  • 1
  • 1
maccettura
  • 10,514
  • 3
  • 28
  • 35