simple binding properties on the page - simple but impossible

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Simple problem - binding Visible property of label to Checked
property of radiobutton on the same form.
How do I do that in VS2005??
Visible="<%# radiob.Checked %>" - DOESN'T WORK
It was so simple in 2003 but how it can be done in VS05
using binding expressions. Theres no controls listing under 'Expressions'
on the designer properties window.
Please help.

Eric
 
Eric,

How about something like this:

in your Page.aspx:
<head runat="server">
<title>Untitled Page</title>
<script language=javascript>
function toggleLabel() {
with (document) {
if (getElementById('CheckBox1').checked) {
getElementById('Label1').style.visibility='visible';
}else{
getElementById('Label1').style.visibility='hidden';
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" onClick="toggleLabel()" />
<asp:Label ID="Label1" runat="server" Text="Label">test</asp:Label>
</div>
</form>
</body>


Does that do what you want?

Regards,
 
Eric,


Or alternatively, in page1.aspx:
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" autopostback=true/>
<asp:Label ID="Label1" runat="server" Text="Label">test</asp:Label>
</div>
</form>
</body>

note the autopostpack=true on the checkbox

and then in the code page, page1.aspx.vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Page.IsPostBack Then
If CheckBox1.Checked Then
Label1.Visible = True
Else
Label1.Visible = False
End If
End If

Good luck,
kathryn
 
Back
Top