Search This Blog

2010/01/17

C#:Creation of composite User Control(without event)

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyGenderControl
{

public class GenderSelector:Control,INamingContainer
{
private Label messageLabel;

public GenderSelector()
{
//constructor
}

string sGender;
public string selectedGender
{
get
{
EnsureChildControls();
return sGender;
}
}

protected void Male_CheckedChanged(object sender, System.EventArgs e)
{
EnsureChildControls();
sGender = "Male";
((Label)Controls[6]).Text = "Male"; ;



}
protected void Female_CheckedChanged(object sender, System.EventArgs e)
{
EnsureChildControls();
sGender = "Female";
messageLabel.Text = "Female";
((Label)Controls[6]).Text = "Female"; ;

}

protected override void CreateChildControls()
{

Label Label1 = new Label();
Label1.Text = "Select Gender";
Controls.Add(Label1);

Controls.Add(new LiteralControl("
"));

RadioButton Male=new RadioButton();
Male.Text="Male";
Controls.Add(Male);
Male.AutoPostBack = true;
Male.GroupName = "Gender";
Male.CheckedChanged += new EventHandler(Male_CheckedChanged);

Controls.Add(new LiteralControl("
"));


RadioButton Female =new RadioButton();
Female.Text = "Female";
Controls.Add(Female);
Female.AutoPostBack = true;
Female.GroupName = "Gender";
Female.CheckedChanged +=new EventHandler(Female_CheckedChanged);

Controls.Add(new LiteralControl("
"));

messageLabel = new Label();
messageLabel.Height = 50;
messageLabel.Width = 300;
messageLabel.Text="Gender Selection";
Controls.Add(messageLabel);
}


}
}

No comments:

Post a Comment