Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hidden parts (C#)

Status
Not open for further replies.

seantuk

Programmer
Mar 22, 2005
62
GB
i have an aspx page, that has two sections to it. the first section (the first half of the page - mostly text, and a couple of buttons) should be visible straight away, but not the second section. when one of these buttons is pressed, i want the first section to dissapear, and the second section to appear.

how can i do this?

ps - i tried putting each section in its own aspx:label, so i could change the visible status. when it got to the browser, the visible label had bcome a span, and the invisible label had been completely removed.
 
.aspx page
Code:
<asp:Button ID="btnShowHide" Runat="server" Text="Toggle Visibility" />
<asp:Panel id="Panel1" runat="server">
<H1>Here is some text in Panel1.</H1>
</asp:Panel>
<br/>
<asp:Panel id="Panel2" runat="server" Visible="False">
<H1>Here is some text in Panel2.</H1>
</asp:Panel>
code behind
Code:
private void Page_Load(object sender, System.EventArgs e)
		{
			int counter;
			if(!IsPostBack)
				counter = 1;
			else
				counter = ((int)ViewState["Counter"]) + 1;

			ViewState["Counter"] = counter;
			if(counter % 2 == 0)
			{
				Panel1.Visible=false;
				Panel2.Visible=true;
			}
			else
			{
				Panel1.Visible=true;
				Panel2.Visible=false;
			}
			
		}
 
i had to set visible to false in page load, to stop the invisible panel from pulling itself out of code before it got to the browser. other from that though, job's a good'n.

cheers veep
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top