Wednesday 13 June 2012

ASP.NET & C# ---- Using RadioButton ,TextBox and Panel control


RadioButton Control:




TextBox Controls:



It is hard to find an ASP.NET application that does not use a TextBox control. It allows the user to interact with the web application you created and hence can provide Dynamic nature to the web application.The venerable HTML input and textarea elements provide alternatives, but they include fewer features and ASP.NET integration.
The basic premise of the TextBox control is accepting user input. This may be as simple as a user entering a username or typing a multiline paragraph. The control provides plenty of methods and properties to work with it via code.


 The TextBox control has the  following properties:
  • AutoPostBack: Boolean value signaling whether the AutoPostBack feature is enabled for the control. This determines if the form will automatically be posted back to the Web server when the contents of the field change.
  • BackColor: The background color of the control. This may be controlled with CSS as well.
  • BorderColor: The border color for the border (if used) displayed around the control.
  • BorderWidth: The width of the border around the control on the page.
  • CausesValidation: Boolean value signaling whether validation is performed when postback of form is executed.
  • Columns: The display width of the TextBox control.
  • CssClass: Allows you to assign a CSS class to the control.
  • Font: The various font attributes associated with the control. The preferred approach is to use CSS, but the Font class contains properties for signaling whether the text appears in bold, italic, strikeout, or underline, as well as font size, name, and more.
  • ForeColor: The color of the text displayed in the field. The preferred technique is CSS.
  • Height: Get or set the height of the control.
  • MaxLength: The maximum number of characters allowed in the field.
  • ReadOnly: Boolean value signaling whether control may be edited by user or just read only.
  • Rows: The number of rows for a TextBox using the multiple line setting.
  • SkinId: Allows you to assign a skin to the TextBox to control its appearance.
  • Text: The text contained within the field.
  • TextMode: The text mode of the control. The legal values are found in the TextBoxMode class with values of single-line, multiline, or password. The password setting masks the text entered, so the password is not displayed — it is available in the code for manipulation and storage.
  • Visible: Boolean value signaling whether the control is visible or hidden.
  • Wrap: Boolean value signaling whether text wraps within the field.

Panel Control:






creating an ASP page with the following information :

  • ·       Page should contain list of radio button controls which can be used to select a language from a list of programming languages
  • ·      The last radio button is labelled other if you select the other radio button the content of the panel control are revealed


languageSelector.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="languageSelector.aspx.cs" Inherits="Radio" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Subject</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <font color="red"><b><asp:Label id="Label2" Text="Select a Language:" Runat="server" /></b></font><br />
    <table>
    <tr><td><asp:RadioButton ID="rb1" Text="C++" GroupName="subject" runat="server"></asp:RadioButton></td></tr>
    <tr><td><asp:RadioButton ID="RadioButton1" Text="C programming" GroupName="subject" runat="server"></asp:RadioButton></td></tr>
    <tr><td><asp:RadioButton ID="RadioButton2" Text="Java" GroupName="subject" runat="server"></asp:RadioButton></td></tr>
    <tr><td><asp:RadioButton ID="RadioButton3" Text="C#" GroupName="subject" runat="server"></asp:RadioButton></td></tr>
    <tr><td><asp:RadioButton ID="RadioButton4" Text="PHP" GroupName="subject" runat="server"></asp:RadioButton></td></tr></tr>
    <tr><td><asp:RadioButton ID="RadioButton5" Text="other" GroupName="subject" runat="server"></asp:RadioButton></td></tr>
    <tr><td><asp:Panel Visible="false" ID="panel2" runat="server">
    <font color="blue"><b><asp:Label id="lblOther" Text="Other Language:" AssociatedControlID="Other" Runat="server" /></b></font><br />
    <asp:TextBox ID="other" runat="server"></asp:TextBox></asp:Panel></td></tr>
    <tr><td><asp:Button ID="submit" Text="submit" runat="server" OnClick="xyz" /></td></tr>
   
    </table>
   
    </div>
    </form>
</body>
</html>

languageSelector.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Radio : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void xyz(object sender, EventArgs e)
    {
        if (RadioButton5.Checked)
        {
            panel2.Visible = true;

        }
        else
        {
            Response.Write("your form was submitted");
        }
    }
}






No comments:

Post a Comment