I have a boolean variable declared at the top of the class, and when the switch is selected on the page, the variable gets true, but when the page reloads, the variable gets reset back to false. One way I dealt with this is to use the static keyword, but I'm not sure if this is the best way to deal with this. Here is a class in which I tried to do something in the Page_Load event, but it still resets the variables to false.
public class SendEmail
{
bool AllSelected;
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
AllSelected = false;
}
}
protected void rbAll_SelectedIndexChanged(object sender, EventArgs e)
{
if(rbAll.SelectedValue == "All")
AllSelected = true;
}
public Send()
{
if(AllSelected)
{
}
}
}
source
share