Subscribe to mailing list?

Always checked ASP.net.

<asp:CheckBox ID="isSubscribed" runat="server" /> Subscribe to mailing list?<br /><br /> <asp:Button runat="server" CssClass="btn" ID="btnPrefUpdate" OnClick="updatePrefs" Text="Update" /><br /><br /> 

This fires in the code behind:

 protected void updatePrefs(object sender, EventArgs e) { Response.Write(isSubscribed.Checked); Response.End(); } 

But it always looks like the truth! Is it checked or not! I know that I am doing it wrong, can someone show me how to properly access this value?

+4
source share
2 answers

as @ Kurt said, it seems to me that you have something in your page_load. if you set the value to Page_Load, make sure it is inside the next if statement

 if(!Page.isPostBack) { isSubscribed.Checked = true; } 
+9
source

You are doing it right. The boolean property of Checked should just say True or False (I even checked it). Does your Page_Load do something with a checkbox? In other words, this is the value of the flag set ever (re) when feedback occurs (button link back).

In your Page_Load method, you can include:

 if (!this.IsPostBack) { // Set default or loaded values for controls } 
+1
source

All Articles