Users Pricing

blog

home / developersection / blogs / panel control in asp.net

Panel Control in ASP.NET

priyanka kushwaha 2765 18 Feb 2015 Updated 18 Feb 2015

In this blog, I’m explaining about Panel control in .Net 


The panel control is used as a control container. It is useful when you want to group controls and work then as a single unit. It provides several properties that allow you to customize the behavior and display of its content. It will render as a div.

Properties of Panel control

Properties                                                          Description

BackImageUrl                                                    Url of background image of the panel.

DefaultButton                                                   Get & sets the identifier for the default button that is contained in the panel control.

Direction                                                              Text direction in the panel.

GroupText                                                         Allows grouping of text as a field.

HorizentalAlign                                                 Horizental alignment of the content in the panel.

scrollBars                                                             Specifies visibility and location of scrollbars within the panel.

Wrap                                                                     Allows text wrapping.

 

Example:
1.       Create a .asp file

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Panelcontrol.aspx.cs" Inherits="AspPanelControl.Panelcontrol" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div style="float:left">
            <asp:Button ID="btn" runat="server" Text="Show" OnClick="btn_Click" /></div>
        <div style="float:right">
           
        <asp:Panel ID="PnlMain" runat="server" GroupingText="Login form" Direction="RightToLeft" HorizontalAlign="Center">
            <table>
                <tr>
                    <td>user Name</td><td>
                        <asp:TextBox ID="txtUser" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>user Password</td><td>
                      
                        <asp:TextBox ID="txtPass" runat="server" contentPlaceHoler="Enter password"></asp:TextBox></td>
                </tr>
 
            </table>
 
        </asp:Panel>
              <asp:Panel ID="PnlAd" runat="server" BorderColor="#990000" BorderStyle="Solid"
 Height="116px" ScrollBars="Both" style="width:278px" DefaultButton="" >
                                        <asp:AdRotator
                                            ID="AdRotator1"
                                            AdvertisementFile="~/XMLFile.xml"
                                            runat="server" Target="_top" Width="500px" />
                     
                    </asp:Panel>
                                   
            </div>
    </div>
    </form>
</body>
</html>

 

 2.    Create a .cs file

 

namespace AspPanelControl
{
    public partial class Panelcontrol : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PnlMain.Visible = false;
          
        }
 
        protected void btn_Click(object sender, EventArgs e)
        {
            if (btn.Text == "Show")
            {
                PnlMain.Visible = true;
                btn.Text ="hide";
                PnlAd.Visible = false;
            }
            else
            {
                PnlAd.Visible = true;
                btn.Text = "Show";
            }
           
        }
    }
}

3.     Create a .XML file

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <ImageUrl>~/images/A.jpg</ImageUrl>
    <width>40px </width>
    <height>50px</height>
    <NavigateUrl>http://www.pastelspace.com/image_detail.php?id=1228</NavigateUrl>
 
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small1</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/images/B.jpg</ImageUrl>
    <width>40px </width>
    <height>50px</height>
    <NavigateUrl>http://www.pastelspace.com/image_detail.php?id=1034</NavigateUrl>
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small2</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/images/C.jpg</ImageUrl>
    <width>40px</width>
    <height>50px</height>
    <NavigateUrl>http://www.dotnetcurry.com</NavigateUrl>
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small</Keyword>
  </Ad>
</Advertisements>