views:

111

answers:

3

I am scratching my head over this, but have no idea what the problem is. My actual code is

<asp:Label ID="Label1" runat="server" Text="abc"
           Visible='<%#Request.QueryString["ListName"] == null %>' />
<asp:GridView ID="gvLists" runat="server"
              Visible='<%#Request.QueryString["ListName"] == null %>' />

As you can see, i am trying to only make the visibility of the object be driven by the querystring. It works fine for the GridView, but doesn't work for a label. I also tried Panel and HyperLink with the same results.

I am sure I could get this working by putting my code in the code-behind, but it won't be as clean.

+3  A: 

<%# %> works only on databound items.

you need to change it to <%= %> (Notice the "=")

Alison
While this didn't work, you did point me in the right direction
Pasha
That won't work, because Visible is a server-side property and `<%= %>` only adds html to render to the client.
Joel Coehoorn
+1  A: 

<%= is uses to print to the page directly and the <%# is used for data binding elements. Here is a great explanation of all the inline code directives.

ryanulit
A: 

Thanks to Alison for pointing me in the right direction. I needed to add Page.DataBind() to my Page_Load event in order for the expression to be evaluated.

Pasha