Reputation: 17
I'm creating an application with one panel my aim is when the page loads the panel should be invisible and on a button click show panel and also be able to hide it with the same button on click. i was able to achieve showing it when one clicks the button, now i'm trying to hide it again on a button click.
public Form1() {
InitializeComponent();
Load += new EventHandler(Form1_Load);
}
public void hidePanels() {
panel2.Visible = false;
}
private void Form1_Load(object sender, EventArgs e) {
hidePanels();
}
private void button1Panel_Click(object sender, EventArgs e) {
hidePanels();
panel2.Visible = true;
}
Upvotes: 0
Views: 6633
Reputation: 1
There is a way to hide your panel(s), the first way
is you can set the property of the panel to false and the second way
is you can put it in your form load.
private void Form1_Load(object sender, EventArgs e)
{
panel2.Visible = false;
}
private void button1Panel_Click(object sender, EventArgs e)
{
panel2.Visible = true;
}
Upvotes: 0
Reputation: 1
private void button1_Click(object sender, EventArgs e)
{
if (panel2.Visible)
panel2.Visible = false;
else
panel2.Visible = true;
}
Upvotes: 0
Reputation: 1435
There isn't much info. Assuming you are using .net -
Your .aspx page should look like this -
<asp:Button ID="btnHide" runat="server" OnClick="btnHide_Click"></asp:Button>
Code behind will look like this -
To hide the panel on page load -
protected void Page_Load(object sender, EventArgs e)
{
panel2.Visible = false;
}
To show the content on button click -
protected void btnHide_Click(object sender, EventArgs e)
{
if(panel2.Visible)
panel2.Visible= false;
else
panel2.Visible= true;
}
Upvotes: 0
Reputation: 2469
First of all, set your panel visibility property to false in the property panel.
In order to hide or show your panel you can use this code :
private void button1Panel_Click(object sender, EventArgs e)
{
panel2.Visible = !panel2.Visible;
}
Upvotes: 2