Some time we need some control that are using again and again in our project ,this controls are combination of different controls (toolbox components) which are accomplished and make a user-defined controls so we use this..
Steps:
1.Add WebUserControl to your project from solution explorer like this below
Right click on highlighted link and click on Add New Item.. and select WebUserControl
now suppose we want to make a feedback form then in design area draw like this below with RadioButtons and normal Button
that * is nothing but a label for accessing the value after click on submit button
now double click on submit and write this code
protected void Button1_Click(object sender, EventArgs e)
{
int i = 0;
if (rbexcel.Checked == true)
{
i = 10;
}
else if (rbvrygood.Checked == true)
{
i = 8;
}
else if (rbngood.Checked == true)
{
i = 5;
}
else if (rbnavg.Checked == true)
{
i = 1;
}
Label1.Text = i.ToString();
}
{
int i = 0;
if (rbexcel.Checked == true)
{
i = 10;
}
else if (rbvrygood.Checked == true)
{
i = 8;
}
else if (rbngood.Checked == true)
{
i = 5;
}
else if (rbnavg.Checked == true)
{
i = 1;
}
Label1.Text = i.ToString();
}
and save this to run this you have to use this WebUserControl.ascx form drag it to place where you want to use
But but but the major thing is left we have to access this value of WebUserControl which we use, to do this use this code in WebUserControl.ascx side
public string fvalue
{
get { return Label1.Text.ToString(); }
set { Label1.Text = value; }
}
and in form or project where you use use Label1 write
Label a1 = (Label)feedback1.FindControl("Label1");
and here feedback1 is my web user control name
enjoy code...bye
No comments:
Post a Comment