We help IT Professionals succeed at work.

asp.net/vb.net issues with checkbox text=session("x")

none of these are working right:

so then once is cklicked in code behind:

if Checkbox.text = "x" then
'do this
end if
<div><asp:CheckBox ID="CheckBox1" Text="<%=Session('GROUP_NAME_1') %>" runat="server" /></div>
					<div><asp:CheckBox ID="CheckBox2" Text='<%=Session("GROUP_NAME_1") %>' runat="server" /></div>
					<div><asp:CheckBox ID="CheckBox3" Text="<%=Session("GROUP_NAME_1") %>" runat="server" /></div>

Open in new window

Watch Question

Most Valuable Expert 2011
Top Expert 2015
You can only use data binding expressions ( <%# ... %> ) in the context of data binding. It looks like you are simply trying assign the value of a Session variable to the Text property, but without actual data binding. Set the value in your code-behind.

Protected Overrides Sub OnInit(ByVal e As EventArgs)
    CheckBox1.Text = Session("GROUP_NAME_1").ToString()
    CheckBox2.Text = Session("GROUP_NAME_1").ToString()
    CheckBox3.Text = Session("GROUP_NAME_1").ToString()
End Sub

Open in new window

Most Valuable Expert 2012
Top Expert 2014


<asp:CheckBox ID="CheckBox1" Text='<%# Session('GROUP_NAME_1') %>' runat="server" />