1.Create User Control with name Enquiry . Drag and drop Text box control on the Enquiry.ascx
set text box id="tbColorName".
2.Create a property in the Enquiry.ascx.cs as shown below.
protected void Page_Load(object sender, EventArgs e)
{
}
private string _color;
public string Color
{
get { return _color; }
set { _color = value; }
}
3.Create a Page with Name UserControlSample.aspx and do below given activities
set text box id="tbColorName".
2.Create a property in the Enquiry.ascx.cs as shown below.
protected void Page_Load(object sender, EventArgs e)
{
}
private string _color;
public string Color
{
get { return _color; }
set { _color = value; }
}
3.Create a Page with Name UserControlSample.aspx and do below given activities
- Drag and drop a button on the aspx page and set id="btnSubmit" Text="Submit"
- Drag and drop the User Control on to the surface of the aspx page. Set UserControl id="Enquiry1".
4.Write the below code in the UserControlSample.aspx.cs
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (var c in Enquiry1.Controls)
{
Type t=c.GetType();
if (t.Name=="TextBox")
{
Enquiry1.Color = ((TextBox)c).Text;
}
}
btnSubmit.BackColor = System.Drawing.Color.FromName(Enquiry1.Color);
}
5.Execute the application by pressing F5.
No comments:
Post a Comment