Click here to Skip to main content
15,921,837 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Page name from webcontrol Pin
kubben6-Mar-07 14:08
kubben6-Mar-07 14:08 
AnswerRe: Page name from webcontrol Pin
Jasmine25016-Mar-07 15:21
Jasmine25016-Mar-07 15:21 
Questionshopping project Pin
reddyamar_uk6-Mar-07 13:06
reddyamar_uk6-Mar-07 13:06 
AnswerRe: shopping project Pin
Jasmine25016-Mar-07 15:09
Jasmine25016-Mar-07 15:09 
GeneralRe: shopping project Pin
siddisagar6-Mar-07 23:58
siddisagar6-Mar-07 23:58 
GeneralRe: shopping project Pin
reddyamar_uk10-Mar-07 11:50
reddyamar_uk10-Mar-07 11:50 
AnswerRe: shopping project Pin
reddyamar_uk10-Mar-07 12:42
reddyamar_uk10-Mar-07 12:42 
QuestionCheckbox always false [modified] Pin
Jasmine25016-Mar-07 11:26
Jasmine25016-Mar-07 11:26 
I have a set of checkboxes in a Repeater control, and every time I submit the page, the Checked property is false, regardless of whether the Checkbox was actually checked or not. I really hate it when my computer disagrees with reality. The Checkbox is checked. I can see it. It's clearly got the little green check-marky-thingy in it... why doesn't my web code see it?

I looked for this issue all over the web, but the sheer number of idiots who didn't know about the "Checked" property are overloading the search results and I'm getting nothing about this particular problem (all I can find is "How do I tell if my checkbox is checked?"). I do have some "clever" code here, but the confounding thing is that this exact same set of code works fine on another page in the site. There is no difference between the two pages except for some formatting changes in the HTML. I have no idea what code is causing the problem, so here's all of it:

Here's the ASP for my Repeater control:

<asp:Repeater ID="RP_contacts" runat="server">
<HeaderTemplate>

	<table style="margin: 0px 10px 0px 10px" cellpadding="2px" cellspacing="0px">
		<tr>
			<td style="border-bottom: solid 1px Black;"><input type="checkbox" onclick="javascript:check_all();" id="allbox" name="allbox" /></td>
			<td style="border-bottom: solid 1px Black;">Contact Name</td>
			<td style="border-bottom: solid 1px Black;">Email Address</td>
			<td style="border-bottom: solid 1px Black;"> Phone</td>
		</tr>
</HeaderTemplate>
<ItemTemplate>
	<tr>
		<td>
			<asp:CheckBox runat="server" ID="cbx" CausesValidation="true" Checked="false" />
			<asp:HiddenField runat="server" ID="HF_contact_id" Value='<%# DataBinder.Eval(Container.DataItem, "contact_id" ) %>' />
		</td>
		<td><a href="contact_edit.aspx?id=<%# DataBinder.Eval(Container.DataItem, "contact_id" ) %>"><%# DataBinder.Eval(Container.DataItem, "name" ) %></a></td>
		<td><a href="email_form.aspx?mailto=<%# DataBinder.Eval(Container.DataItem, "contact_id" ) %>"><%# DataBinder.Eval(Container.DataItem, "email" ) %></a></td>
		<td><%# DataBinder.Eval(Container.DataItem, "phone" ) %></td>
	</tr>
</ItemTemplate>
<FooterTemplate>
	</table>
</FooterTemplate>
</asp:Repeater>


And here's the code-behind where I'm trying to access the checkboxes:

public ArrayList get_checked_contacts() {
    ArrayList result = new ArrayList();
    foreach (RepeaterItem i in RP_contacts.Items) {
        CheckBox c = (CheckBox)(i.FindControl("cbx"));
        if (c != null && c.Checked) {
            result.Add(Int32.Parse(((HiddenField)i.FindControl("HF_contact_id")).Value));
        }
    }
    return result;
}


When this code reaches the "If" statement, the checkbox is never null, and never Checked. What is up with that? It's identifying the control correctly, but it's not retrieving the property correctly.

I check for postbacks.
I have the viewstate enabled (but I don't need it)
I have a small javascript on this page (no errors).
The code is in a UserControl.
The UserControl is in a MasterPage.
The code works fine in another page. The code is copy-pasted so it's definitely the same. The MasterPage/UserControl heirarchy is the same in both places. I have repeated the copy/paste several times just to make sure D'Oh! | :doh:
This is also broken when I put it at the top-level of a standard ASPX page (no MasterPage or UserControls) - this says it's an actual problem with the code, and I got lucky with the page that's working correctly, which means my good page will probably fail at some point in the future. I would like to avoid that Smile | :)
I have tried various combinations of the properties of the Checkbox control, and the problem does not seem to be affected by EnableViewState, CausesValidation, Checked, or AutoPostBack (I can't have AutoPostback on this page, but it doesn't fix the problem anyway)

Eeeeek... I'm totally out of ideas. Maybe a fresh set of eyes is what I need... Any insight into this problem will be greatly appreciated.



-- modified at 18:19 Tuesday 6th March, 2007

"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

AnswerRe: Checkbox always false Pin
PandemoniumPasha6-Mar-07 17:55
PandemoniumPasha6-Mar-07 17:55 
GeneralRe: Checkbox always false Pin
Jasmine25017-Mar-07 5:53
Jasmine25017-Mar-07 5:53 
QuestionPrice of making WEB PORTAL Pin
Dragoslav Zaric6-Mar-07 8:36
Dragoslav Zaric6-Mar-07 8:36 
AnswerRe: Price of making WEB PORTAL Pin
Vasudevan Deepak Kumar6-Mar-07 9:16
Vasudevan Deepak Kumar6-Mar-07 9:16 
AnswerRe: Price of making WEB PORTAL Pin
Jasmine25016-Mar-07 10:39
Jasmine25016-Mar-07 10:39 
QuestionWidth Problem Pin
Mr Emash6-Mar-07 6:51
Mr Emash6-Mar-07 6:51 
AnswerRe: Width Problem Pin
Vasudevan Deepak Kumar6-Mar-07 9:16
Vasudevan Deepak Kumar6-Mar-07 9:16 
GeneralRe: Width Problem Pin
Mr Emash6-Mar-07 12:50
Mr Emash6-Mar-07 12:50 
GeneralRe: Width Problem Pin
N a v a n e e t h6-Mar-07 18:28
N a v a n e e t h6-Mar-07 18:28 
QuestionCreating Custom Providers Pin
Skoder6-Mar-07 6:50
Skoder6-Mar-07 6:50 
AnswerRe: Creating Custom Providers Pin
Jasmine25016-Mar-07 15:23
Jasmine25016-Mar-07 15:23 
QuestionRef Javascript File Pin
tadhg886-Mar-07 6:33
tadhg886-Mar-07 6:33 
AnswerRe: Ref Javascript File Pin
kubben6-Mar-07 7:10
kubben6-Mar-07 7:10 
AnswerRe: Ref Javascript File Pin
ToddHileHoffer6-Mar-07 8:20
ToddHileHoffer6-Mar-07 8:20 
GeneralRe: Ref Javascript File Pin
kubben6-Mar-07 9:58
kubben6-Mar-07 9:58 
GeneralRe: Ref Javascript File Pin
tadhg886-Mar-07 23:57
tadhg886-Mar-07 23:57 
GeneralRe: Ref Javascript File Pin
ToddHileHoffer8-Mar-07 3:26
ToddHileHoffer8-Mar-07 3:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.