<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: ASP.Net CheckBoxes should be able to have values</title>
	<atom:link href="http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/feed/" rel="self" type="application/rss+xml" />
	<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/</link>
	<description>Discussion on Development in Several Different Flavours</description>
	<pubDate>Sun, 12 Oct 2008 00:14:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Andrew</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-38177</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 08 Oct 2008 14:58:25 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-38177</guid>
		<description>Sorry, it stripped out my asp code:

asp:CheckBox runat="server" value="04" id="control"</description>
		<content:encoded><![CDATA[<p>Sorry, it stripped out my asp code:</p>
<p>asp:CheckBox runat=&#8221;server&#8221; value=&#8221;04&#8243; id=&#8221;control&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-38175</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 08 Oct 2008 14:12:27 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-38175</guid>
		<description>I found an almost decent way of doing this:

Declare your checkbox:



Then you can programatically add any values by looping through your controls, looking for checkboxes, and doing this:

Control.InputAttributes.Add("value", Control.Attributes("value"))

It will complain that value is not a valid attribute on the asp:checkbox tag, but it works.</description>
		<content:encoded><![CDATA[<p>I found an almost decent way of doing this:</p>
<p>Declare your checkbox:</p>
<p>Then you can programatically add any values by looping through your controls, looking for checkboxes, and doing this:</p>
<p>Control.InputAttributes.Add(&#8221;value&#8221;, Control.Attributes(&#8221;value&#8221;))</p>
<p>It will complain that value is not a valid attribute on the asp:checkbox tag, but it works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-37563</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 03 Oct 2008 07:55:10 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-37563</guid>
		<description>I managed to sort this out by using the CheckedChanged event handler. All you need to do is programmatically change the checked value, then you can reference the checkbox.checked value directly because it fires before the page load event

like so....

protected void yourcheckbox_CheckedChanged(object sender, EventArgs e)
    {
        if (yourcheckbox.Checked == true)
        {
            yourcheckbox.Checked = false;
        }
        else
        {
            yourcheckbox.Checked = true;
        }
    }

Hope this helps. :-)</description>
		<content:encoded><![CDATA[<p>I managed to sort this out by using the CheckedChanged event handler. All you need to do is programmatically change the checked value, then you can reference the checkbox.checked value directly because it fires before the page load event</p>
<p>like so&#8230;.</p>
<p>protected void yourcheckbox_CheckedChanged(object sender, EventArgs e)<br />
    {<br />
        if (yourcheckbox.Checked == true)<br />
        {<br />
            yourcheckbox.Checked = false;<br />
        }<br />
        else<br />
        {<br />
            yourcheckbox.Checked = true;<br />
        }<br />
    }</p>
<p>Hope this helps. :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wuz</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-35889</link>
		<dc:creator>wuz</dc:creator>
		<pubDate>Sun, 21 Sep 2008 13:39:15 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-35889</guid>
		<description>I think Ryan's custom class is the way to go, and as heared 100 times before we can just use InputAttributes to render the property to html:

public class CheckBoxWithValue : CheckBox
{
public string Value
{
get { return ViewState["Value"] as string; }
set { ViewState["Value"] = value; }
}

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            this.InputAttributes["value"] = this.Value;
        }
}</description>
		<content:encoded><![CDATA[<p>I think Ryan&#8217;s custom class is the way to go, and as heared 100 times before we can just use InputAttributes to render the property to html:</p>
<p>public class CheckBoxWithValue : CheckBox<br />
{<br />
public string Value<br />
{<br />
get { return ViewState["Value"] as string; }<br />
set { ViewState["Value"] = value; }<br />
}</p>
<p>protected override void OnPreRender(EventArgs e)<br />
        {<br />
            base.OnPreRender(e);<br />
            this.InputAttributes["value"] = this.Value;<br />
        }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: n01r3n3x</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-32018</link>
		<dc:creator>n01r3n3x</dc:creator>
		<pubDate>Tue, 12 Aug 2008 14:49:57 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-32018</guid>
		<description>You know the checkboxlist, well, even though the values don't render on the page, you can still access them from the code on the serverside using asp.net, because you can select more than one value from a checkboxlist, there cannot be a single SelectedValue, somewhere along the way Microsoft stuffed up there inheritance, or thought it would be okay to leave it as is (Which, it is, really...) 

You can get around this quite simply by iterating through the checkboxlist as follows.

for (int i = 0; i &#60; cbo.Items.Count; i++)
{
  if (cbo.Items[i].Selected)
  {
    cbo.Items[i].Value)
  }
}

To locate the control on the page I've used a recursive script that goes through all the controls within a placeholder, (Or the whole page if you want), then if it finds a checkbox list, it classifies it and uses the above code to obtain the values.

Any questions contact me info at noirenex dot com</description>
		<content:encoded><![CDATA[<p>You know the checkboxlist, well, even though the values don&#8217;t render on the page, you can still access them from the code on the serverside using asp.net, because you can select more than one value from a checkboxlist, there cannot be a single SelectedValue, somewhere along the way Microsoft stuffed up there inheritance, or thought it would be okay to leave it as is (Which, it is, really&#8230;) </p>
<p>You can get around this quite simply by iterating through the checkboxlist as follows.</p>
<p>for (int i = 0; i &lt; cbo.Items.Count; i++)<br />
{<br />
  if (cbo.Items[i].Selected)<br />
  {<br />
    cbo.Items[i].Value)<br />
  }<br />
}</p>
<p>To locate the control on the page I&#8217;ve used a recursive script that goes through all the controls within a placeholder, (Or the whole page if you want), then if it finds a checkbox list, it classifies it and uses the above code to obtain the values.</p>
<p>Any questions contact me info at noirenex dot com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-31528</link>
		<dc:creator>Nigel</dc:creator>
		<pubDate>Tue, 05 Aug 2008 15:43:48 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-31528</guid>
		<description>There is a similar problem with the name attribute. I'd like to render checkbox controls for use with client side scripts.

Although ChkBox.InputAttributes["name"] = "customName"; does add the name attribute to the HTML page. ASP makes this usless as it also puts in it's duplicate name attribute.</description>
		<content:encoded><![CDATA[<p>There is a similar problem with the name attribute. I&#8217;d like to render checkbox controls for use with client side scripts.</p>
<p>Although ChkBox.InputAttributes["name"] = &#8220;customName&#8221;; does add the name attribute to the HTML page. ASP makes this usless as it also puts in it&#8217;s duplicate name attribute.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David J Bunge</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-28077</link>
		<dc:creator>David J Bunge</dc:creator>
		<pubDate>Mon, 30 Jun 2008 16:49:54 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-28077</guid>
		<description>The "Value" attribute shows in my browser.
In my ASPX page:


Rendered HTML:
Family

So, the value shows in HTML for me. I'm using ASP.Net 2.0, and I do get the Validation Warning on Visual Studio. However, I'm ignoring it, as the attribute is rendered. Just wanted to share.</description>
		<content:encoded><![CDATA[<p>The &#8220;Value&#8221; attribute shows in my browser.<br />
In my ASPX page:</p>
<p>Rendered HTML:<br />
Family</p>
<p>So, the value shows in HTML for me. I&#8217;m using ASP.Net 2.0, and I do get the Validation Warning on Visual Studio. However, I&#8217;m ignoring it, as the attribute is rendered. Just wanted to share.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Phelps</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-26376</link>
		<dc:creator>Tim Phelps</dc:creator>
		<pubDate>Fri, 13 Jun 2008 17:39:03 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-26376</guid>
		<description>Here's the solution:

Use the InputAttributes property rather than the Attributes property of the CheckBox class.

cb.InputAttributes["value"] = "foo";

Works like a charm.

Found this on Dave Parslow's blog:

http://www.daveparslow.com/2007/08/assigning-value-to-aspnet-checkbox.html</description>
		<content:encoded><![CDATA[<p>Here&#8217;s the solution:</p>
<p>Use the InputAttributes property rather than the Attributes property of the CheckBox class.</p>
<p>cb.InputAttributes["value"] = &#8220;foo&#8221;;</p>
<p>Works like a charm.</p>
<p>Found this on Dave Parslow&#8217;s blog:</p>
<p><a href="http://www.daveparslow.com/2007/08/assigning-value-to-aspnet-checkbox.html" rel="nofollow">http://www.daveparslow.com/2007/08/assigning-value-to-aspnet-checkbox.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Bielski</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-26275</link>
		<dc:creator>Michael Bielski</dc:creator>
		<pubDate>Wed, 11 Jun 2008 21:22:02 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-26275</guid>
		<description>Ryan, your custom class doesn't work. The value attribute is STILL not rendered in the final HTML on the page. It may be in the viewstate, but the tag doesn't have it. If I ever find a solution, I'll post it.</description>
		<content:encoded><![CDATA[<p>Ryan, your custom class doesn&#8217;t work. The value attribute is STILL not rendered in the final HTML on the page. It may be in the viewstate, but the tag doesn&#8217;t have it. If I ever find a solution, I&#8217;ll post it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Tremaine</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-22705</link>
		<dc:creator>Ryan Tremaine</dc:creator>
		<pubDate>Sun, 06 Apr 2008 23:36:34 +0000</pubDate>
		<guid isPermaLink="false">http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-22705</guid>
		<description>I agree they should have included it. Easy to get around however:

public class CheckBoxWithValue : CheckBox
    {
        public string Value
        {
            get { return ViewState["Value"] as string; }
            set { ViewState["Value"] = value; }
        }
    }</description>
		<content:encoded><![CDATA[<p>I agree they should have included it. Easy to get around however:</p>
<p>public class CheckBoxWithValue : CheckBox<br />
    {<br />
        public string Value<br />
        {<br />
            get { return ViewState["Value"] as string; }<br />
            set { ViewState["Value"] = value; }<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
</channel>
</rss>
