0

I want to display:none html element in asp.net something like this :)

<ul style="<% if(Page.Request.QueryString["Search"] == null) { "display: none"} %>">

Any suggestion or example would be great for me, thanks.

Manuel Escrig
  • 2,825
  • 1
  • 27
  • 36
Obaid Ahmed
  • 596
  • 1
  • 3
  • 16

2 Answers2

2

what about

<% = (Page.Request.QueryString["Search"] == null ? "display:none":string.Empty) %>
Legends
  • 21,202
  • 16
  • 97
  • 123
0

Why not use javascript for this? It will be much cleaner to keep client side code separate.

there are a ton of ways to get a query string in JS here is one

Then you can check and add the class with jquery.

HTML:

<ul id="search">

    <li>test</li>

</ul>

Javascript:

// from https://stackoverflow.com/questions/4656843/jquery-get-querystring-from-url

    function getUrlVars()
    {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }

    var search = getUrlVars()["Search"];

    if(!search)
    {
        $("#search").css("display","none")
    }

http://jsfiddle.net/aaLw9mx8/

Community
  • 1
  • 1
Aaron
  • 1,361
  • 1
  • 13
  • 30