Question

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.

Was it helpful?

Solution 3

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.

OTHER TIPS

<%# %> works only on databound items.

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

<%= 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top