Problem with controlling visibility of linkbutton

G

Guest

Hi Guys, i have the following linkbutton with visibility conditionally
controlled from codebehind:

<asp:LinkButton id="test" style="Z-INDEX: 101; LEFT: 464px; POSITION:
absolute; TOP: 160px" runat="server" Visible="<%# boolVisible
%>">LinkButton</asp:LinkButton>

In Codebehind:
Public boolVisible As Boolean
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
If (Convert.ToString(Session("glVar_gAdmin")).Equals("G")) Then
boolVisible = True
Else
boolVisible = False
End If InitializeComponent()
End Sub


Funny part is that i have same code on other page and it works perfectly. I
dont know what am i doing wrong..Can someone shed some light on this>?

thanks

Manny
 
K

Karl Seguin

<%# is for databinding....

you'd need to use <%= boolVisible %>

better yet, instead of doing it this ugly way, why not take advantage of why
..net has to offer?

protected test as LinkButton

Page_Init
If (Convert.ToString(Session("glVar_gAdmin")).Equals("G")) Then
test.Visible = True
Else
test.Visible = False
End If

End Sub

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
E

Eliyahu Goldin

--
Eliyahu

Karl Seguin said:
<%# is for databinding....

you'd need to use <%= boolVisible %>

better yet, instead of doing it this ugly way, why not take advantage of why
.net has to offer?

protected test as LinkButton

Page_Init
If (Convert.ToString(Session("glVar_gAdmin")).Equals("G")) Then
test.Visible = True
Else
test.Visible = False
End If

End Sub

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
perfectly.
 
E

Eliyahu Goldin

Oops, pressed Send before writing.

Databinding is both correct and relevant in this case. It is as ugly here as
in any other place where you can replace it with handling ItemDataBound
event in the code.

Eliyahu
 
E

Eliyahu Goldin

A control doesn't need to be a special one. You can databind any property of
any control. And you can databind to any protected Page property. I myself
use this sort of databinding occasionally.

Eliyahu
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top