blog

Home / DeveloperSection / Blogs / Panel Control in ASP.NET

Panel Control in ASP.NET

priyanka kushwaha2276 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

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Panelcontrol.aspx.cs"Inherits="AspPanelControl.Panelcontrol"%>
 
<!DOCTYPEhtml>
 
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
    <title></title>
</head>
<body>
    <formid="form1"runat="server">
    <div>
        <divstyle="float:left">
            <asp:ButtonID="btn"runat="server"Text="Show"OnClick="btn_Click"/></div>
        <divstyle="float:right">
           
        <asp:PanelID="PnlMain"runat="server"GroupingText="Login form"Direction="RightToLeft"HorizontalAlign="Center">
            <table>
                <tr>
                    <td>user Name</td><td>
                        <asp:TextBoxID="txtUser"runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>user Password</td><td>
                      
                        <asp:TextBoxID="txtPass"runat="server"contentPlaceHoler="Enter password"></asp:TextBox></td>
                </tr>
 
            </table>
 
        </asp:Panel>
              <asp:PanelID="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
{
    publicpartialclassPanelcontrol : System.Web.UI.Page
    {
        protectedvoid Page_Load(object sender, EventArgs e)
        {
            PnlMain.Visible = false;
          
        }
 
        protectedvoid 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

<?xmlversion="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>

Updated 18-Feb-2015

Leave Comment

Comments

Liked By