Conditional coding

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

On a webform I need some links to appear only if some condition is met.
Basically I am looking for something like this;

if x=y then
<-- generate html to display the relevant link 1-->
end if

if a=b then
<-- generate html to display the relevant link 2-->
end if

Could someone please provide a link to such an example?

Thanks

Regards
 
Make the links to server HyperLinks controls. Set their Visible property
like this:
myLink1.Visible = (x=y)

Eliyahu
 
Forgot to mention. Likely, you will want to do it in the Page_Load event. If
the conditions are in the data sources you are binding to, you will want to
use either ItemDataBound or PreRender event.

Eliyahu
 
Works nicely except there are <br>s between each linkbutton and when a
linkbutton is not visible the space is still there giving away the fact that
something is missing. How can I get rid of extra space around a link when
the link is not visible?

Thanks

Regards
 
John,

Use a literal control instead of the hyperlink. The literal control can be
filled with whatever you want and the text inside it will be rendered
without change. Just drop the literal control on the page where you need it
and then use a string builder to create your links like this:

Dim MyStringBuilder As New System.Text.StringBuilder

If x=y Then
MyStringBuilder.Append("<a href=www.msn.com
target=_blank>www.msn.com</a>")
End If

If a=b Then
MyStringBuilder.Append("<a href=www.msn.com
target=_blank>www.msn.com</a><br>")
End If

Literal1.Text = MyStringBuilder.ToString

This way you'll be able to control when you need a break or not.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
How did the <br>s get there in the first place? Must be from your layout.
Look at the layout, find what generates them and delete the source. You
might want to layout the page with html tables.

Eliyahu
 
Works nicely except there are <br>s between each linkbutton and
when a linkbutton is not visible the space is still there giving
away the fact that something is missing. How can I get rid of
extra space around a link when the link is not visible?

John,

You could put the link button and <br> in a panel, and then set the
panel's visibility.
 

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

Back
Top