HI guys, I'm having a problem with hiding and showing a panel that contains a text box. Basically the panel is hidden and whenever a radio box is selected the panel should show but it won't work.
Here is the code:
<div class="expensesForm">
<div class="control-group">
<label class="control-label" for="rent">Rent</label>
<div class="controls">
<asp:RadioButton ID="rent" runat="server" GroupName="expenses" OnCheckedChanged="CheckedChanged" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="car">Car</label>
<div class="controls">
<asp:RadioButton ID="car" runat="server" GroupName="Expenses" OnCheckedChanged="CheckedChanged" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="bills">Bills</label>
<div class="controls">
<asp:RadioButton ID="bills" runat="server" GroupName="Expenses" OnCheckedChanged="CheckedChanged" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="food" AssociatedControlID="food">Food</label>
<div class="controls">
<asp:RadioButton ID="food" runat="server" GroupName="Expenses" OnCheckedChanged="CheckedChanged" />
</div>
</div>
<div class="control-group">
<asp:Panel ID="amount" runat="server">
<label class="control-label" for="bills">Enter amount</label>
<div class="controls">
<asp:TextBox ID="TextBox1" runat="server" Visible="True"></asp:TextBox>
</div>
</asp:Panel>
</div>
</div>
And the code behind here, however when I select the radio button the panel doesn't appear:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {//returns false the first time the page is displayed true when redisplayed
initForm();
}
}
private void initForm() {
amount.Visible = false;//hide amount info on page load
rent.Checked = false;//unselect all radio buttons
car.Checked = false;
bills.Checked = false;
food.Checked = false;
}
protected void CheckedChanged(object sender, EventArgs e)
{
amount.Visible = true;//showamount info on page load
}
}