Boolean Visible Property problem

J

John South

Hi

I'm new to asp.net and c# and I've got stuck on an apparently simple
problem:

I'm trying to make a HyperLink dynamically visible/invisible.

This is the HTML:

<asp:HyperLink Runat="server" Text="Back"
NavigateUrl='HeadingList.aspx' Visible='<%=isNotTop()%>' />

This is the in the .cs file:
public string isNotTop()
{
return ("false");
}


I get the error message:
<%=isNotTop()%> is not a valid value for Boolean.

I've tried getting isNotTop() to return a boolean but it doesn't help.

I've done something similar within a DataList using <%#...%> and it's
worked OK.

Can someone guide me in the right direction here?


Cheers
John South
Pangbourne UK
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi John,

Yes it would be much better to bind the Visible property to your function by
using the
<%#...%> construct:

<asp:HyperLink Runat="server" Text="Back"
NavigateUrl='HeadingList.aspx' Visible='<%# isNotTop()%>' />

and make sure isNotTop() returns a Boolean value.

You will have to call DataBind() on that control though
to make it work.
 
I

Ignacio Machin \( .NET/ C# MVP \)

HI John

You are mixing the old ASP model with the new one :)

You have two options, you can set it in the code simply using an assignment
like
theHyperLink.Visible = false;
you can do this from anywhere in the code behind.

You can use the DataBind mechanist, for this you have to change the <%= %>
tag for <%# %>
Please make note that it's a complete new feature !!
if so you have to change the type of the function to the correct type of
the Visible property:
public bool isNotTop()
{
return false;
}


Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top