I created a user control with a couple of radio buttons on it.
When the user clicks on one of the radio buttons an event gets passed
up along with the value of the radio button clicked.
I then created a form with several of these controls on it.
Each one of these controls effects another item on my form.
I can easily write a code for each of the Controls on my form but since
they all do similar things I'd like to create one function that handles
the events for all the controls.
My problem : I need to know the name of the user control given to in on
the form and not from the actual control. ie..
private void one_CheckedChanged(object sender, System.EventArgs e)
{
string lblname =((Control)(sender)).Name.ToString();
//get the item number
string txtnumber;
if(lblname.Length==8)
txtnumber=lblname.Substring(lblname.Length-1,1);
else
txtnumber=lblname.Substring(lblname.Length-2,2);
// get the user controls associated with that number
UserControl1 ucAlign = (UserControl1)
FindControl("ucAlignLN"+txtnumber);
Label lb = (Label) FindControlLabel("lbltextBox"+txtnumber);
TextBox tb = (TextBox) FindControlLabel("textBox"+txtnumber);
// changed the alignment on the screen
switch(ucAlign.Alignment)
{
case "LEFT":
lb.Text = tb.Text.PadRight(50,' ').Replace(" ","*");
lb.Text = lb.Text.Substring(0,50);
break;
case "RIGHT":
lb.Text = tb.Text.PadLeft(50,' ').Replace(" ","*");
lb.Text = lb.Text.Substring(lb.Text.Length-50,lb.Text.Length);
break;
}
}
Unfortunately this line gives me the name of the radiobutton from the
control and not the name of the control givien to it on the form.
string lblname =((Control)(sender)).Name.ToString();
So how do i get the name given to the user control on the form?
Thanks.