Since your control is in a LayoutTemplate, you need to use this:
CheckBox termsCheckBox = LoginAuth.FindControl("TermsCheckbox") as CheckBox;
termsCheckBox.Checked = true;
Question
I have an asp:Login and a within that. I want to add a checkbox within that but everytime I do, I can't see it in the code behind.
<asp:Login id="LoginAuth" runat="server">
<LayoutTemplate>
....
<asp:CheckBox ID="TermsCheckbox" runat="server" OnCheckedChanged="AgreeTerms_OnChecked" />
Doing this in the code behind gives me an error:
LoginAuth.TermsCheckbox.Checked = true or TermsCheckbox.Checked = true
It doesn't seem to see TermsCheckbox anywhere. How do I fix this?
Solution
Since your control is in a LayoutTemplate, you need to use this:
CheckBox termsCheckBox = LoginAuth.FindControl("TermsCheckbox") as CheckBox;
termsCheckBox.Checked = true;