Hi! It may seems easy but since I am learning I would like to know How I can change text of Lable.
I have RadioButtonList(rbl1 and rbl2) and Label1 and when someone click on rbl2, how i can change text of Label1. Also, I have set rbl1 as default selected. So when somone click back to rbl1, the default text of Label1 should be appearing.
Thanks for your answer.
R Patel
Niradhip ChakrabortyPosted Aug 11, 2008, 5:02 PM
Go to property and Set the AutoPostBack property to true for the radiobuttonlist.
and try out the following code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//check the first item of radio button list on first time of page load.
RadioButtonList1.SelectedIndex = 0;
Label1.Text = RadioButtonList1.SelectedItem.Text.ToString();
}
else
{
Label1.Text = RadioButtonList1.SelectedItem.Text.ToString();
}
}
Note: You also can do it by using java script.
Edit: Oh sorry, Ryan replied already while I am sending the post.
PalPosted Aug 12, 2008, 9:22 AM
Thanks for all of the answer
RP
Ryan AlfordPosted Aug 11, 2008, 4:54 PM
Label1.Text = "Text Changed";
and of course, if your label is not named "Label1", then you need to put the name of your label there.
PalPosted Aug 11, 2008, 2:46 PM
Hi! Muhammad
I have radiobuttonlist and it seems it needs different answer. can you tell me how that can work.
Thanks
R Patel
Muhammad Shahid FarooqPosted Aug 11, 2008, 2:37 PM
write the following code in the click event of rbl1:
Label1.text = "Label1"
write the following code in the click event of rbl2:
Label1.text = "Text Changed"