Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain this: CheckBox checkbox = (CheckBox)sender;

Tags:

c#

asp.net

While going through the checkBox I found there is written

CheckBox checkbox = (CheckBox)sender

on checkBox1_CheckedChanged event.

Please explain what it means?

like image 751
Shalni Avatar asked Sep 23 '10 11:09

Shalni


People also ask

What is checkbox asp net?

ASP.NET Web Forms CheckBox. It is used to get multiple inputs from the user. It allows user to select choices from the set of choices. It takes user input in yes or no format. It is useful when we want multiple choices from the user.

Which of the following Web Control provide check change event?

The OnCheckedChanged event handler of the ASP.Net Checkbox control allows us to handle the click event of a checkbox at the server side that is raised when the user clicks the checkbox control to changes it checked state.


1 Answers

The line simply casts sender to a CheckBox.

Why?

The event handler signature for the CheckedChanged event is:

CheckChanged(object sender, EventArgs e)

So, you need to cast sender back to a CheckBox if you want to use any CheckBox specific functionality - object doesn't have much that you can use...

This way the checkbox variable can be used to get the checkbox Id and operate on the checkbox.

like image 124
Oded Avatar answered Sep 28 '22 08:09

Oded