DotNet Tutorials

Server Intellect

 How to use Panel Control using ASP.NET 2.0 and C#.NET

This tutorial will show you how to use panel control using ASP.NET 2.0 and C# 2.0
This tutorial will show you how to use panel control using ASP.NET 2.0 and C# 2.0

Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!

This tutorial only using the default namespace.
You need to stuff with your user name in the STEP 1, you will get into next step in the same of page while being to click FristPrevStep button, we use the Visible attribute of panel control to carry out here thus of result.

We use the PrevStep and NextStep event to do the work.

The code as follows.

protected void PrevStep(Object sender, EventArgs e)
{
string CurrentPanel = "Panel" + ViewState["PanelSeed"].ToString();
ViewState["PanelSeed"] = (int)ViewState["PanelSeed"] - 1;
string PrevPanel = "Panel" + ViewState["PanelSeed"].ToString();
Panel p = (Panel)FindControl(CurrentPanel);
p.Visible = false;
p = (Panel)FindControl(PrevPanel);
p.Visible = true;
}
protected void NextStep(object sender, EventArgs e)
{
string CurrentPanel = "Panel" + ViewState["PanelSeed"].ToString();
ViewState["PanelSeed"] = (int)ViewState["PanelSeed"] + 1;
string NextPanel = "Panel" + ViewState["PanelSeed"].ToString();
Panel p = (Panel)FindControl(CurrentPanel);
p.Visible = false;
p = (Panel)FindControl(NextPanel);
p.Visible = true;
if ((int)ViewState["PanelSeed"] == 2)
{
FUserName.Text = UserName.Text;
FAddress.Text = Address.Text;
FZipCode.Text = ZipCode.Text;
FComment.Text = Comment.Text;
}
}

The front end PanelCsharp.aspx page looks something like this:

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

<div align="center"><fieldset style="width: 437px">
<asp:Panel id="Panel0" runat="server" Width="434px" >
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; width: 70%; height: 32px;" bordercolor="#111111">
<tr>
<td width="100%" colspan="3" bgcolor="#339966" align="center">
<font color="#ffff99">Step 1 Input user name</font></td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" style="height: 25px">
Username:</td>
<td width="33%" bgcolor="#eeeddb" style="height: 25px">
<asp:TextBox id="UserName" runat="Server" Width="156px" /></td>
<td bgcolor="#eeeddb" style="width: 34%; height: 25px">
<asp:Button id="FristNextStep" Text="Next step" runat="server" OnClick="NextStep"/></td>
</tr>
</table>
</asp:Panel>

<asp:Panel id="Panel1" runat="server" Width="328px">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; width: 100%;" bordercolor="#111111" height="32">
<tr>
<td width="100%" colspan="2" bgcolor="#339966" align="center" style="height: 15px">
<font color="#ffff99">Step 2 Input your information</font></td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" height="16">
Username:</td>
<td bgcolor="#eeeddb" height="16" style="width: 79%">
<%=UserName.Text%> </td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" height="16">
Address:</td>
<td bgcolor="#eeeddb" height="16" style="width: 79%">
<asp:TextBox id="Address" runat="server" /> </td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" height="16">
ZIP Code:</td>
<td bgcolor="#eeeddb" height="16" style="width: 79%"><asp:TextBox id="ZipCode" runat="server" /> </td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" height="16">
Comment:</td>
<td bgcolor="#eeeddb" height="16" style="width: 79%">
<asp:TextBox id="Comment" TextMode="MultiLine" Wrap="True" Rows="10" runat="Server" /> </td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" style="height: 16px"> </td>
<td bgcolor="#eeeddb" style="width: 79%; height: 16px">
<asp:Button id="FristPrevStep" Text="Previous step" OnClick="PrevStep" runat="server"/>

<asp:Button id="SecondNextStep" Text="Next step" OnClick="NextStep" runat="server" /> </td>
</tr>
</table>
</asp:Panel>

<asp:Panel id="Panel2" runat="server" Width="321px">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; width: 98%;" bordercolor="#111111" height="32">
<tr>
<td width="100%" colspan="2" bgcolor="#339966" align="center" style="height: 15px">
<font color="#ffff99">Step 4 Information list</font></td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" height="16">
Username:</td>
<td bgcolor="#eeeddb" height="16" style="width: 67%">
<asp:Label id="FUserName" runat="Server" /> </td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" style="height: 16px">
Address:</td>
<td bgcolor="#eeeddb" style="width: 67%; height: 16px">
<asp:Label id="FAddress" runat="Server" /> </td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" height="16">
ZIP Code:</td>
<td bgcolor="#eeeddb" height="16" style="width: 67%">
<asp:Label id="FZipCode" runat="Server" /> </td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" height="16">
Comment:</td>
<td bgcolor="#eeeddb" height="16" style="width: 67%">
<asp:Label id="FComment" runat="Server" /> </td>
</tr>
<tr>
<td width="33%" bgcolor="#eeeddb" height="16"> </td>
<td bgcolor="#eeeddb" height="16" style="width: 67%">
<asp:Button id="SecondPrevStep" Text="Previous step" OnClick="PrevStep" runat="server" />

<asp:Button id="FinishStep" Text="Fnish" OnClick="NextStep" runat="server" /> </td>
</tr>
</table>
</asp:Panel>
<asp:Panel id="Panel3" runat="server" Width="268px">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; width: 92%;" bordercolor="#111111">
<tr>
<td colspan="3" bgcolor="#339966" align="center" style="width: 494px">
<font color="#ffff99">Thank you</font> </td>
</tr>
<tr>
<td colspan="3" bgcolor="#eeeddb" style="width: 494px; height: 20px">
Thank you</td>
</tr>
</table>
</asp:Panel>
</fieldset>
</div>

The flow for the code behind page is as follows

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class PanelCsharp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ViewState["PanelSeed"] = 0;
Panel0.Visible = true;
Panel1.Visible = false;
Panel2.Visible = false;
Panel3.Visible = false;
}
}

protected void PrevStep(Object sender, EventArgs e)
{
string CurrentPanel = "Panel" + ViewState["PanelSeed"].ToString();
ViewState["PanelSeed"] = (int)ViewState["PanelSeed"] - 1;
string PrevPanel = "Panel" + ViewState["PanelSeed"].ToString();
Panel p = (Panel)FindControl(CurrentPanel);
p.Visible = false;
p = (Panel)FindControl(PrevPanel);
p.Visible = true;
}

protected void NextStep(object sender, EventArgs e)
{
string CurrentPanel = "Panel" + ViewState["PanelSeed"].ToString();
ViewState["PanelSeed"] = (int)ViewState["PanelSeed"] + 1;
string NextPanel = "Panel" + ViewState["PanelSeed"].ToString();
Panel p = (Panel)FindControl(CurrentPanel);
p.Visible = false;
p = (Panel)FindControl(NextPanel);
p.Visible = true;
if ((int)ViewState["PanelSeed"] == 2)
{
FUserName.Text = UserName.Text;
FAddress.Text = Address.Text;
FZipCode.Text = ZipCode.Text;
FComment.Text = Comment.Text;
}
}
}




Looking for the VB.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect