<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<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>
	<lastBuildDate>Fri, 23 Jul 2010 11:05:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Jason</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/comment-page-1/#comment-136</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Wed, 01 Apr 2009 17:04:57 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-136</guid>
		<description>I took what Ryan and WUZ provided and created a server control. This will appear in the toolbox.
I had to convert it to VB for this web application.

&lt;pre class=&quot;brush: vb&quot;&gt;Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace UI.WebControls
    &lt;ToolboxData(&quot;&quot;)&gt; _
    Public Class CheckBoxWithValue
        Inherits System.Web.UI.WebControls.CheckBox

         Property Value() As String
            Get
                Dim s As String = CStr(ViewState(&quot;Value&quot;))
                If s Is Nothing Then
                    Return String.Empty
                Else
                    Return s
                End If
            End Get
            Set(ByVal value As String)
                ViewState(&quot;Value&quot;) = value
            End Set
        End Property

        Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
            MyBase.OnPreRender(e)
            Me.InputAttributes(&quot;Value&quot;) = Me.Value
        End Sub

        Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
            writer.Write(Text)
        End Sub

    End Class
End Namespace
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I took what Ryan and WUZ provided and created a server control. This will appear in the toolbox.<br />
I had to convert it to VB for this web application.</p>
<pre class="brush: vb">Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace UI.WebControls
    &lt;ToolboxData("")&gt; _
    Public Class CheckBoxWithValue
        Inherits System.Web.UI.WebControls.CheckBox

         Property Value() As String
            Get
                Dim s As String = CStr(ViewState("Value"))
                If s Is Nothing Then
                    Return String.Empty
                Else
                    Return s
                End If
            End Get
            Set(ByVal value As String)
                ViewState("Value") = value
            End Set
        End Property

        Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
            MyBase.OnPreRender(e)
            Me.InputAttributes("Value") = Me.Value
        End Sub

        Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
            writer.Write(Text)
        End Sub

    End Class
End Namespace
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/comment-page-1/#comment-138</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 08 Oct 2008 14:58:25 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-138</guid>
		<description>Sorry, it stripped out my asp code:

asp:CheckBox runat=&quot;server&quot; value=&quot;04&quot; id=&quot;control&quot;</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-page-1/#comment-137</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 08 Oct 2008 14:12:27 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-137</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(&quot;value&quot;, Control.Attributes(&quot;value&quot;))

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(&#8220;value&#8221;, Control.Attributes(&#8220;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-page-1/#comment-134</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 03 Oct 2008 08:55:10 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-134</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....

&lt;pre class=&quot;brush: csharp&quot;&gt;protected void yourcheckbox_CheckedChanged(object sender, EventArgs e)
    {
        if (yourcheckbox.Checked == true)
        {
            yourcheckbox.Checked = false;
        }
        else
        {
            yourcheckbox.Checked = true;
        }
    }
&lt;/pre&gt;

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>
<pre class="brush: csharp">protected void yourcheckbox_CheckedChanged(object sender, EventArgs e)
    {
        if (yourcheckbox.Checked == true)
        {
            yourcheckbox.Checked = false;
        }
        else
        {
            yourcheckbox.Checked = true;
        }
    }
</pre>
<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-page-1/#comment-139</link>
		<dc:creator>wuz</dc:creator>
		<pubDate>Sun, 21 Sep 2008 14:39:15 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-139</guid>
		<description>I think Ryan&#039;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:

&lt;pre class=&quot;brush: csharp&quot;&gt;public class CheckBoxWithValue : CheckBox
{
public string Value
{
get { return ViewState[&quot;Value&quot;] as string; }
set { ViewState[&quot;Value&quot;] = value; }
}

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            this.InputAttributes[&quot;value&quot;] = this.Value;
        }
}
&lt;/pre&gt;
</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>
<pre class="brush: csharp">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;
        }
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel</title>
		<link>http://devsushi.com/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/comment-page-1/#comment-135</link>
		<dc:creator>Nigel</dc:creator>
		<pubDate>Tue, 05 Aug 2008 15:43:48 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-135</guid>
		<description>There is a similar problem with the name attribute. I&#039;d like to render checkbox controls for use with client side scripts.

Although ChkBox.InputAttributes[&quot;name&quot;] = &quot;customName&quot;; does add the name attribute to the HTML page. ASP makes this usless as it also puts in it&#039;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-page-1/#comment-131</link>
		<dc:creator>David J Bunge</dc:creator>
		<pubDate>Mon, 30 Jun 2008 16:49:54 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-131</guid>
		<description>The &quot;Value&quot; attribute shows in my browser.
In my ASPX page:


Rendered HTML:
Family

So, the value shows in HTML for me. I&#039;m using ASP.Net 2.0, and I do get the Validation Warning on Visual Studio. However, I&#039;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-page-1/#comment-132</link>
		<dc:creator>Tim Phelps</dc:creator>
		<pubDate>Fri, 13 Jun 2008 17:39:03 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-132</guid>
		<description>Here&#039;s the solution:

Use the InputAttributes property rather than the Attributes property of the CheckBox class.

cb.InputAttributes[&quot;value&quot;] = &quot;foo&quot;;

Works like a charm.

Found this on Dave Parslow&#039;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-page-1/#comment-133</link>
		<dc:creator>Michael Bielski</dc:creator>
		<pubDate>Wed, 11 Jun 2008 21:22:02 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-133</guid>
		<description>Ryan, your custom class doesn&#039;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&#039;t have it. If I ever find a solution, I&#039;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-page-1/#comment-130</link>
		<dc:creator>Ryan Tremaine</dc:creator>
		<pubDate>Mon, 07 Apr 2008 00:36:34 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2007/07/16/aspnet-checkboxes-should-be-able-to-have-values/#comment-130</guid>
		<description>I agree they should have included it. Easy to get around however:

&lt;pre class=&quot;brush: csharp&quot;&gt;public class CheckBoxWithValue : CheckBox
    {
        public string Value
        {
            get { return ViewState[&quot;Value&quot;] as string; }
            set { ViewState[&quot;Value&quot;] = value; }
        }
    }
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I agree they should have included it. Easy to get around however:</p>
<pre class="brush: csharp">public class CheckBoxWithValue : CheckBox
    {
        public string Value
        {
            get { return ViewState["Value"] as string; }
            set { ViewState["Value"] = value; }
        }
    }
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
