<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Paul Mrozowski's Blog - ASP.NET</title>
    <link>http://www.rcs-solutions.com/blog/</link>
    <description>A day in the life (of a developer)</description>
    <language>en-us</language>
    <copyright>Paul Mrozowski / RCS Solutions, Inc.</copyright>
    <lastBuildDate>Wed, 26 Nov 2008 01:33:27 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>paulm@rcs-solutions.com</managingEditor>
    <webMaster>paulm@rcs-solutions.com</webMaster>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=0a733f71-4d24-4cc6-9896-de948f7656e4</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,0a733f71-4d24-4cc6-9896-de948f7656e4.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,0a733f71-4d24-4cc6-9896-de948f7656e4.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=0a733f71-4d24-4cc6-9896-de948f7656e4</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I received this error on a page which had previously been working. That morning I
had updated our site, so I was expecting some issues, but this error doesn't really
tell you much. We have a maintenance screen which displays a list of records in a
grid. When you click on an edit link the grid converts into an "in place" editor (a
UI metaphor I thought I'd like when I initially put the form together but which, as
it turns out, I really hate). 
</p>
        <p>
A user had reported that when they clicked on a button which saves this record that
it wasn't closing and updating the list. We are using Telerik web controls for most
of the site so I figured it had to do with them since I updated a number of pages,
including our master page, to start using the RAD AJAX version of the controls instead
of their previous version. It seems this error was being caused because I had added
an instance of the RadAjaxManager control to the master page, and I already had an
instance of a AjaxManager (older version) on the content page itself. Both managers
were conflicting with one another, which caused this error. 
</p>
        <p>
All I needed to change was the "RadAjaxManager" markup code to a "RadAjaxManagerProxy"
and that resolved this particular error. 
</p>
        <img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=0a733f71-4d24-4cc6-9896-de948f7656e4" />
      </body>
      <title>Sys.InvalidOperationException: A control is already associated with the element.</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,0a733f71-4d24-4cc6-9896-de948f7656e4.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2008/11/26/SysInvalidOperationExceptionAControlIsAlreadyAssociatedWithTheElement.aspx</link>
      <pubDate>Wed, 26 Nov 2008 01:33:27 GMT</pubDate>
      <description>&lt;p&gt;
I received this error on a page which had previously been working. That morning I
had updated our site, so I was expecting some issues, but this error doesn't really
tell you much. We have a maintenance screen which displays a list of records in a
grid. When you click on an edit link the grid converts into an "in place" editor (a
UI metaphor I thought I'd like when I initially put the form together but which, as
it turns out, I really hate). 
&lt;p&gt;
A user had reported that when they clicked on a button which saves this record that
it wasn't closing and updating the list. We are using Telerik web controls for most
of the site so I figured it had to do with them since I updated a number of pages,
including our master page, to start using the RAD AJAX version of the controls instead
of their previous version. It seems this error was being caused because I had added
an instance of the RadAjaxManager control to the master page, and I already had an
instance of a AjaxManager (older version) on the content page itself. Both managers
were conflicting with one another, which caused this error. 
&lt;p&gt;
All I needed to change was the "RadAjaxManager" markup code to a "RadAjaxManagerProxy"
and that resolved this particular error. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=0a733f71-4d24-4cc6-9896-de948f7656e4" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,0a733f71-4d24-4cc6-9896-de948f7656e4.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=9ceaccd8-befb-4b38-991e-087e3a98a5bb</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,9ceaccd8-befb-4b38-991e-087e3a98a5bb.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,9ceaccd8-befb-4b38-991e-087e3a98a5bb.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=9ceaccd8-befb-4b38-991e-087e3a98a5bb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
ASP.NET makes it fairly simple to enable security on content hosted inside of ASP.NET
(ASPX pages, ASHX, etc.) just by enabling form-based authentication. Any attempt to
access those pages will automatically get redirected to a login page for authentication.
However, static content (HTM or HTML pages) for example aren't passed through the
ASP.NET pipeline, so anyone can access that content (unless you've set-up something
like Basic Authentication) - your user's aren't required to authenticate before accessing
the content. 
</p>
        <p>
It turns out it's pretty simple to get IIS to pass requests to ASP.NET and let it
handle any permissions, logging, etc. that you may want to apply - in fact, this is
how ASP.NET itself hooks into IIS. The first thing you need to do is open the IIS
Manager. Right-click on the website and select properties. Click on the "Home Directory"
tab, then click on the Configuration button. That will display a list of application
extensions and the EXE/DLL that is responsible for those filetypes. We're going to
handle any files with a .HTM extension, so click on Add. In the "Executable" field
enter something like "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
- I just copied this from the ASPX extension and pasted it in. In the extension field
enter ".HTM". Leave everything else as-is and click on OK. If you want to map HTML
files as well, repeat this procedure and enter ".HTML" as the extension (w/o the quotes).
Hit OK to all the prompts to close the various dialogs. At this point IIS will forward
requests for files with either .HTM or .HTML files to ASP.NET.  
</p>
        <p>
  
</p>
        <p>
          <a href="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/SecuringStaticContentThroughASP.NET_12679/Properties_2.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="642" alt="Properties" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/SecuringStaticContentThroughASP.NET_12679/Properties_thumb.png" width="568" border="0" />
          </a>
        </p>
        <p>
          <a href="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/SecuringStaticContentThroughASP.NET_12679/AddExtMap_4.png">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="472" alt="AddExtMap" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/SecuringStaticContentThroughASP.NET_12679/AddExtMap_thumb_1.png" width="671" border="0" />
          </a>
        </p>
        <p>
Now we need to tell ASP.NET how to handle these file types by editing the web.config
file to add an HTTP handler for these types. In the system.web section, we're going
to map these types to use a built-in handler called "StaticFileHandler". The web.config
will look something like this: 
</p>
        <p>
          <font face="Courier New">&lt;system.web&gt;<br />
   &lt;httpHandlers&gt;<br />
      &lt;add path="*.htm" verb="*" type="System.Web.StaticFileHandler"
/&gt;<br />
      &lt;add path="*.html" verb="*" type="System.Web.StaticFileHandler"
/&gt;</font>
        </p>
        <p>
Save the web.config. At this point requests for .HTM and .HTML will be passed through
ASP.NET and it will pass the request to an instance of the StaticFileHandler class.
If you have form-based security, you will automatically be redirected to log in as
well before being able to view any HTM or HTML pages (assuming you've protected all
pages). The main downside to pushing this through ASP.NET is that IIS can no longer
handle accessing HTM/HTML pages, which will reduce the efficiency and scalability
of the site. However, with most sites this isn't really much of an issue. The other
issue I've noticed is that the StaticFileHandler class automatically sets the caching
of the item served up to 1 day (regardless of what you've configured in IIS), and
there isn't any way of overridding this behavior short of writing your own handler. 
</p>
        <p>
BTW - This can be used to secure other content as well, for example, PDF files, JPG's,
GIF's, etc. You would just need to add an entry in IIS like we did for HTM/HTML files
and make an associated entry in the web.config. In the example above I was specifically
mapping each content type on an as-needed basis. I should also mention that you can
also just use a wildcard mapping in IIS (option below the one we used) which will
map any file types not in the first list. In that case you don't need to modify the
web.config - it should be handled by the DefaultHttpHandler class (ASP.NET 2.0 and
later - this isn't the case for 1.1). 
</p>
        <p>
If you're interesting in writing your own handler for static files, I did some searching
and found <a href="http://msmvps.com/blogs/omar/archive/2008/06/30/deploy-asp-net-mvc-on-iis-6-solve-404-compression-and-performance-problems.aspx" target="_blank">this</a>.
He includes code for his own implementation of a static file handler which includes
compression and caching. 
</p>
        <p>
  
</p>
        <p>
          <strong>Links</strong>
        </p>
        <a href="http://msmvps.com/blogs/omar/archive/2008/06/30/deploy-asp-net-mvc-on-iis-6-solve-404-compression-and-performance-problems.aspx">http://msmvps.com/blogs/omar/archive/2008/06/30/deploy-asp-net-mvc-on-iis-6-solve-404-compression-and-performance-problems.aspx</a>
        <img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=9ceaccd8-befb-4b38-991e-087e3a98a5bb" />
      </body>
      <title>Securing Static Content Through ASP.NET</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,9ceaccd8-befb-4b38-991e-087e3a98a5bb.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2008/09/24/SecuringStaticContentThroughASPNET.aspx</link>
      <pubDate>Wed, 24 Sep 2008 01:00:44 GMT</pubDate>
      <description>&lt;p&gt;
ASP.NET makes it fairly simple to enable security on content hosted inside of ASP.NET
(ASPX pages, ASHX, etc.) just by enabling form-based authentication. Any attempt to
access those pages will automatically get redirected to a login page for authentication.
However, static content (HTM or HTML pages) for example aren't passed through the
ASP.NET pipeline, so anyone can access that content (unless you've set-up something
like Basic Authentication) - your user's aren't required to authenticate before accessing
the content. 
&lt;/p&gt;
&lt;p&gt;
It turns out it's pretty simple to get IIS to pass requests to ASP.NET and let it
handle any permissions, logging, etc. that you may want to apply - in fact, this is
how ASP.NET itself hooks into IIS. The first thing you need to do is open the IIS
Manager. Right-click on the website and select properties. Click on the "Home Directory"
tab, then click on the Configuration button. That will display a list of application
extensions and the EXE/DLL that is responsible for those filetypes. We're going to
handle any files with a .HTM extension, so click on Add. In the "Executable" field
enter something like "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
- I just copied this from the ASPX extension and pasted it in. In the extension field
enter ".HTM". Leave everything else as-is and click on OK. If you want to map HTML
files as well, repeat this procedure and enter ".HTML" as the extension (w/o the quotes).
Hit OK to all the prompts to close the various dialogs. At this point IIS will forward
requests for files with either .HTM or .HTML files to ASP.NET.&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/SecuringStaticContentThroughASP.NET_12679/Properties_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="642" alt="Properties" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/SecuringStaticContentThroughASP.NET_12679/Properties_thumb.png" width="568" border="0"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;a href="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/SecuringStaticContentThroughASP.NET_12679/AddExtMap_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="472" alt="AddExtMap" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/SecuringStaticContentThroughASP.NET_12679/AddExtMap_thumb_1.png" width="671" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Now we need to tell ASP.NET how to handle these file types by editing the web.config
file to add an HTTP handler for these types. In the system.web section, we're going
to map these types to use a built-in handler called "StaticFileHandler". The web.config
will look something like this: 
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;lt;system.web&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;httpHandlers&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add path="*.htm" verb="*" type="System.Web.StaticFileHandler"
/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add path="*.html" verb="*" type="System.Web.StaticFileHandler"
/&amp;gt;&lt;/font&gt; 
&lt;/p&gt;
&lt;p&gt;
Save the web.config. At this point requests for .HTM and .HTML will be passed through
ASP.NET and it will pass the request to an instance of the StaticFileHandler class.
If you have form-based security, you will automatically be redirected to log in as
well before being able to view any HTM or HTML pages (assuming you've protected all
pages). The main downside to pushing this through ASP.NET is that IIS can no longer
handle accessing HTM/HTML pages, which will reduce the efficiency and scalability
of the site. However, with most sites this isn't really much of an issue. The other
issue I've noticed is that the StaticFileHandler class automatically sets the caching
of the item served up to 1 day (regardless of what you've configured in IIS), and
there isn't any way of overridding this behavior short of writing your own handler. 
&lt;/p&gt;
&lt;p&gt;
BTW - This can be used to secure other content as well, for example, PDF files, JPG's,
GIF's, etc. You would just need to add an entry in IIS like we did for HTM/HTML files
and make an associated entry in the web.config. In the example above I was specifically
mapping each content type on an as-needed basis. I should also mention that you can
also just use a wildcard mapping in IIS (option below the one we used) which will
map any file types not in the first list. In that case you don't need to modify the
web.config - it should be handled by the DefaultHttpHandler class (ASP.NET 2.0 and
later - this isn't the case for 1.1). 
&lt;/p&gt;
&lt;p&gt;
If you're interesting in writing your own handler for static files, I did some searching
and found &lt;a href="http://msmvps.com/blogs/omar/archive/2008/06/30/deploy-asp-net-mvc-on-iis-6-solve-404-compression-and-performance-problems.aspx" target="_blank"&gt;this&lt;/a&gt;.
He includes code for his own implementation of a static file handler which includes
compression and caching. 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Links&lt;/strong&gt;
&lt;/p&gt;
&lt;a href="http://msmvps.com/blogs/omar/archive/2008/06/30/deploy-asp-net-mvc-on-iis-6-solve-404-compression-and-performance-problems.aspx"&gt;http://msmvps.com/blogs/omar/archive/2008/06/30/deploy-asp-net-mvc-on-iis-6-solve-404-compression-and-performance-problems.aspx&lt;/a&gt;&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=9ceaccd8-befb-4b38-991e-087e3a98a5bb" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,9ceaccd8-befb-4b38-991e-087e3a98a5bb.aspx</comments>
      <category>ASP.NET</category>
      <category>IIS</category>
    </item>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=ed775c89-3e6a-43c5-aaea-7d79166991d3</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,ed775c89-3e6a-43c5-aaea-7d79166991d3.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,ed775c89-3e6a-43c5-aaea-7d79166991d3.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=ed775c89-3e6a-43c5-aaea-7d79166991d3</wfw:commentRss>
      <title>Live Checkboxes in ASP.NET Grid</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,ed775c89-3e6a-43c5-aaea-7d79166991d3.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2008/04/16/LiveCheckboxesInASPNETGrid.aspx</link>
      <pubDate>Wed, 16 Apr 2008 02:18:15 GMT</pubDate>
      <description>&lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;
&lt;/div&gt;
&lt;p&gt;
One request that comes up from time to time is to embed a checkbox inside of an ASP.NET
grid control for boolean data. 
&lt;p&gt;
Unfortunately, one of the downsides to this is that the controls are "read only" -
they don't let you check or uncheck them 
&lt;p&gt;
without putting the row into edit mode. That works, but in some cases this isn't all
that great either. What do you do if you just want a checkbox on each row, that's
"live" and causes a postback as you check/uncheck items? Thankfully this doesn't take
much code but figuring out the first time can be really painful. To get the "live"
checkbox, just wrap it inside of a template. (In the example code I created a new
Web Form named "GridCheckbox"). 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;@&lt;/span&gt; &lt;span style="color: #a31515"&gt;Page&lt;/span&gt; &lt;span style="color: red"&gt;Language&lt;/span&gt;&lt;span style="color: blue"&gt;="C#"&lt;/span&gt; &lt;span style="color: red"&gt;AutoEventWireup&lt;/span&gt;&lt;span style="color: blue"&gt;="true"&lt;/span&gt; &lt;span style="color: red"&gt;CodeBehind&lt;/span&gt;&lt;span style="color: blue"&gt;="GridCheckbox.aspx.cs"&lt;/span&gt; &lt;span style="color: red"&gt;Inherits&lt;/span&gt;&lt;span style="color: blue"&gt;="WebApplication1.GridCheckbox"&lt;/span&gt; &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: #a31515"&gt;DOCTYPE&lt;/span&gt; &lt;span style="color: red"&gt;html&lt;/span&gt; &lt;span style="color: red"&gt;PUBLIC&lt;/span&gt; &lt;span style="color: blue"&gt;"-//W3C//DTD
XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span style="color: blue"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;html&lt;/span&gt; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt; &lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;head&lt;/span&gt; &lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;="Head1"&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Untitled
Page&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;form&lt;/span&gt; &lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;="form1"&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridView&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;="grdList"&lt;/span&gt; &lt;span style="color: red"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue"&gt;="false"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: red"&gt;onrowdatabound&lt;/span&gt;&lt;span style="color: blue"&gt;="grdList_RowDataBound"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateField&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;CheckBox&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;="chkItem"&lt;/span&gt; &lt;span style="color: red"&gt;Checked&lt;/span&gt;&lt;span style="color: blue"&gt;='&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;#
Container.DataItem &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;'&lt;/span&gt; &lt;span style="color: red"&gt;AutoPostBack&lt;/span&gt;&lt;span style="color: blue"&gt;="True"&lt;/span&gt; &lt;span style="color: red"&gt;OnCheckedChanged&lt;/span&gt;&lt;span style="color: blue"&gt;="CheckChanged"/&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateField&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Columns&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridView&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;form&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
Make sure you set the "AutoPostBack" to true. Then set it's OnCheckedChanged event
handler to call your server side code. 
&lt;/p&gt;
&lt;p&gt;
Now let's add some code to the Page_Load to give our grid something to bind to: 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;EventArgs&lt;/span&gt; e)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;bool&lt;/span&gt;[] items = { &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;true&lt;/span&gt; };
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (!Page.IsPostBack)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.grdList.DataSource
= items;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.grdList.DataBind();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
In my example code, I'm just binding to a simple boolean collection to keep things
simple. Now we need an event handler to respond to our checkbox event:
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; CheckChanged(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;EventArgs&lt;/span&gt; e)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
The code doesn't do anything yet but at this point you might be wondering how we figure
out which checkbox we checked - normally, your grid is bound to a different row in
some table. Each checkbox is related to that specific row. How or where do we get
that from? The grid isn't much help in this case because it's not raising the event.
If we were using a Button we could set it's CommandName and/or CommandArgument properties
to hold something like the primary key of the row in our table. The checkbox control
doesn't have any such properties. ASP.NET controls have an InputAttributes collection
where you can place name/value pairs - this information is passed to the client (and
back to the server), so it makes this relatively painless. 
&lt;/p&gt;
&lt;p&gt;
First, add an event to onRowDataBound of the grid (already shown in the ASPX above). 
&lt;asp:gridview id="grdList" runat="server" onrowdatabound="grdList_RowDataBound" autogeneratecolumns="false"&gt;Now add the event in our code-behind: 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; grdList_RowDataBound(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;GridViewRowEventArgs&lt;/span&gt; e)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
We can't reference the control directly by name, since it was embedded in the grid
and ASP.NET has made sure it's uniquely named. Let's use the FindControl method to
do this. I've also added the code to add a Value attribute and added a member called
m_row. I'm just using this so we can have a different value on each and every row
of the grid. In a real application this is where you'd pull the primary key value
from your datasource (probably using e.Row.DataItem). 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; m_row
= 0;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; grdList_RowDataBound(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;GridViewRowEventArgs&lt;/span&gt; e)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;CheckBox&lt;/span&gt; chk = e.Row.FindControl(&lt;span style="background: #e5e5e5"&gt;"chkItem"&lt;/span&gt;) &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CheckBox&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (chk != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; chk.InputAttributes.Add(&lt;span style="background: #e5e5e5"&gt;"Value"&lt;/span&gt;, &lt;span style="color: blue"&gt;this&lt;/span&gt;.m_row.ToString());
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.m_row++;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;
Now we're just about done - all that's left is retrieving this value back on the server
when the Checkbox is checked or unchecked: 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; CheckChanged(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;EventArgs&lt;/span&gt; e)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;CheckBox&lt;/span&gt; chk = sender &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CheckBox&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt; val = &lt;span style="background: #e5e5e5"&gt;""&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (chk != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = chk.InputAttributes[&lt;span style="background: #e5e5e5"&gt;"Value"&lt;/span&gt;];
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;
So our completed codebehind page looks like this: 
&lt;/p&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Collections;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Configuration;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Data;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Web;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Web.Security;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Web.UI;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Web.UI.HtmlControls;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Web.UI.WebControls;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Web.UI.WebControls.WebParts;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;namespace&lt;/span&gt; WebApplication1
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;partial&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;GridCheckbox&lt;/span&gt; :
System.Web.UI.&lt;span style="color: #2b91af"&gt;Page&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; m_row
= 0;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;EventArgs&lt;/span&gt; e)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;bool&lt;/span&gt;[]
items = { &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;true&lt;/span&gt; };
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (!Page.IsPostBack)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.grdList.DataSource
= items;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.grdList.DataBind();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; CheckChanged(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;EventArgs&lt;/span&gt; e)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;CheckBox&lt;/span&gt; chk
= sender &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CheckBox&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt; val
= &lt;span style="background: #e5e5e5"&gt;""&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (chk
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
val = chk.InputAttributes[&lt;span style="background: #e5e5e5"&gt;"Value"&lt;/span&gt;];
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; grdList_RowDataBound(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;GridViewRowEventArgs&lt;/span&gt; e)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;CheckBox&lt;/span&gt; chk
= e.Row.FindControl(&lt;span style="background: #e5e5e5"&gt;"chkItem"&lt;/span&gt;) &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CheckBox&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (chk
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
chk.InputAttributes.Add(&lt;span style="background: #e5e5e5"&gt;"Value"&lt;/span&gt;, &lt;span style="color: blue"&gt;this&lt;/span&gt;.m_row.ToString());
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.m_row++;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
Now when you run this every time you check or uncheck an item you should see the page
post-back (set a breakpoint on CheckChanged). You can now update your data, or whatever
else you need to do in response to this event.&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=ed775c89-3e6a-43c5-aaea-7d79166991d3" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,ed775c89-3e6a-43c5-aaea-7d79166991d3.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=cdd5812e-7ceb-4ac0-8d51-bc7941cc35dc</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,cdd5812e-7ceb-4ac0-8d51-bc7941cc35dc.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,cdd5812e-7ceb-4ac0-8d51-bc7941cc35dc.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=cdd5812e-7ceb-4ac0-8d51-bc7941cc35dc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This has hit me more than once already. If you create an HTTP Handler (ASHX) file,
by default the context object reference (passed in to ProcessRequest) doesn't contain
a reference to the Session object, so attempting to access context.Session will fail. 
</p>
        <p>
The fix is to add a "using System.Web.SessionState" to the using section, then inherit
from the IReadOnlySessionState interface. 
</p>
        <p>
  
</p>
        <p>
Ex. 
</p>
        <p>
  
</p>
        <p>
          <font face="Courier New">using System.Web.SessionState;</font>
        </p>
        <p>
          <font face="Courier New">public class MyAshx : IHttpHandler, IReadOnlySessionState<br />
{</font>
        </p>
        <p>
          <font face="Courier New">}</font>
        </p>
        <p>
  
</p>
        <p>
This will give you read only access to the session state. If you need to add to the
session, inherit from IRequiresSessionState instead.
</p>
        <img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=cdd5812e-7ceb-4ac0-8d51-bc7941cc35dc" />
      </body>
      <title>Session State in ASHX</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,cdd5812e-7ceb-4ac0-8d51-bc7941cc35dc.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2008/04/04/SessionStateInASHX.aspx</link>
      <pubDate>Fri, 04 Apr 2008 23:15:49 GMT</pubDate>
      <description>&lt;p&gt;
This has hit me more than once already. If you create an HTTP Handler (ASHX) file,
by default the context object reference (passed in to ProcessRequest) doesn't contain
a reference to the Session object, so attempting to access context.Session will fail. 
&lt;p&gt;
The fix is to add a "using System.Web.SessionState" to the using section, then inherit
from the IReadOnlySessionState interface. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Ex. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;font face="Courier New"&gt;using System.Web.SessionState;&lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;public class MyAshx : IHttpHandler, IReadOnlySessionState&lt;br&gt;
{&lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;}&lt;/font&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
This will give you read only access to the session state. If you need to add to the
session, inherit from IRequiresSessionState instead.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=cdd5812e-7ceb-4ac0-8d51-bc7941cc35dc" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,cdd5812e-7ceb-4ac0-8d51-bc7941cc35dc.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=f9feda22-090b-459b-b636-5257a225d500</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,f9feda22-090b-459b-b636-5257a225d500.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,f9feda22-090b-459b-b636-5257a225d500.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=f9feda22-090b-459b-b636-5257a225d500</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm not sure when this was added (if it's just in VS 2008 or if it's been there since
VS 2005), but I just noticed this while I was updating the website (I just added a
download section). I created a new master page for the site, then updated the original
home page with one that used the new master page. The master page is now home to the
header, menu, and footer with a "hole" punched in the middle for my custom content.
Then I added the download page and started adding files. You might not have noticed
before, but the home page has a footer which moves with the browser; it basically
sticks to the bottom by using a bit of CSS. This works well on the home page, and
appeared to be OK while I was working on the download page. That is. up until the
number of downloads forced the page to scroll. At that point the footer actually sat
on top of the downloads listed, which isn't quite the effect I was hoping for. If
I changed the footer style to float, it worked well for the download page but was
pretty ugly for the home page (since it's a bit sparse the footer was like 1 inch
below the header). 
</p>
        <p>
I played around with the idea of embedding a div tag in my home page that had relative
heights to force the content back to where it belonged. That didn't work out too nicely,
so I briefly thought about using JavaScript to handle this instead. That seemed like
overkill, so I nixed that idea. If the footer was defined in my home page content
section, I could just override the CSS style for that one page. However, it's in the
master page. I could define two CSS files instead, but I really didn't like the idea
of having to maintain two stylesheets. That's when I noticed a new section in my master
page - a content holder for the head section of the page:
</p>
        <p>
 <a href="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/NiceASP.NETMasterPageEnhancement_13261/MPContent_2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="134" alt="MPContent" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/NiceASP.NETMasterPageEnhancement_13261/MPContent_thumb.png" width="535" border="0" /></a></p>
        <p>
 
</p>
        <p>
That made it really simple to just add an overriding style (with the same name as
the one defined in my CSS file) into the home page content. I had to move the CSS
link above the ContentPlaceHolder so that it was defined before my overriding style.
Then I just added a &lt;style&gt; section inside of the header and I was good to go.
This isn't earth shaking stuff, but it was a nice addition.
</p>
        <img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=f9feda22-090b-459b-b636-5257a225d500" />
      </body>
      <title>Nice ASP.NET Master Page Enhancement</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,f9feda22-090b-459b-b636-5257a225d500.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2007/11/29/NiceASPNETMasterPageEnhancement.aspx</link>
      <pubDate>Thu, 29 Nov 2007 03:01:27 GMT</pubDate>
      <description>&lt;p&gt;
I'm not sure when this was added (if it's just in VS 2008 or if it's been there since
VS 2005), but I just noticed this while I was updating the website (I just added a
download section). I created a new master page for the site, then updated the original
home page with one that used the new master page. The master page is now home to the
header, menu, and footer with a "hole" punched in the middle for my custom content.
Then I added the download page and started adding files. You might not have noticed
before, but the home page has a footer which moves with the browser; it basically
sticks to the bottom by using a bit of CSS. This works well on the home page, and
appeared to be OK while I was working on the download page. That is. up until the
number of downloads forced the page to scroll. At that point the footer actually sat
on top of the downloads listed, which isn't quite the effect I was hoping for. If
I changed the footer style to float, it worked well for the download page but was
pretty ugly for the home page (since it's a bit sparse the footer was like 1 inch
below the header). 
&lt;/p&gt;
&lt;p&gt;
I played around with the idea of embedding a div tag in my home page that had relative
heights to force the content back to where it belonged. That didn't work out too nicely,
so I briefly thought about using JavaScript to handle this instead. That seemed like
overkill, so I nixed that idea. If the footer was defined in my home page content
section, I could just override the CSS style for that one page. However, it's in the
master page. I could define two CSS files instead, but I really didn't like the idea
of having to maintain two stylesheets. That's when I noticed a new section in my master
page - a content holder for the head section of the page:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&lt;a href="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/NiceASP.NETMasterPageEnhancement_13261/MPContent_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="134" alt="MPContent" src="http://www.rcs-solutions.com/blog/content/binary/WindowsLiveWriter/NiceASP.NETMasterPageEnhancement_13261/MPContent_thumb.png" width="535" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
That made it really simple to just add an overriding style (with the same name as
the one defined in my CSS file) into the home page content. I had to move the CSS
link above the ContentPlaceHolder so that it was defined before my overriding style.
Then I just added a &amp;lt;style&amp;gt; section inside of the header and I was good to go.
This isn't earth shaking stuff, but it was a nice addition.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=f9feda22-090b-459b-b636-5257a225d500" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,f9feda22-090b-459b-b636-5257a225d500.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=232647a7-8706-4a10-8a79-d08df3a3e6fa</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,232647a7-8706-4a10-8a79-d08df3a3e6fa.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,232647a7-8706-4a10-8a79-d08df3a3e6fa.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=232647a7-8706-4a10-8a79-d08df3a3e6fa</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Imagine this scenario: You want to create a simple user control that you can use in
a few web pages. It incorporates a few JavaScript functions that change the UI slightly
during a mouse click; pretty standard stuff. The script isn't particularly useful
in other controls, so putting it into a common library doesn't make much sense. It
could be broken out into it's own library, which can at least be cached by a browser.
But that introduces another dependency in the hosting page - you have to remember
to include a reference to this JS library before things will work. The easiest thing
to do would be to just include the JS code inside the user control itself (I'm skipping
the option of embedding it as a resource; maybe another day). Including the code in
the control is pretty simple and seamless. Until you drop two instances of the same
control on page. What you'll find (like I did) is that your JS code is now rendered
one time for each control. That's not very cool. In fact, you run into this same issue
even if you decide to move the code into it's own library - you end up with more than
one reference to the library. 
</p>
        <p>
  
</p>
        <p>
A relatively simple way around all this is the ClientScriptManager class that is available
hanging off the Page object as ClientScript. It lets you register JS code to be rendered
into the main page. You can also check for the existence of the registered code (to
keep from registering it more than once, regardless of the number of controls on the
page). In my case, since I'm just embedding the code right in the page, there are
only two methods required for this: IsClientScriptBlockRegistered and RegisterClientScriptBlock. 
</p>
        <p>
  
</p>
        <p>
The routines use the object type and the passed in name as a key; if you don't pass
it into IsClientScriptBlockRegistered (or the other variants) the routines will use
the Page's type. I'd suggest always passing in something besides the page type (for
example, the user control type). This will keep you from running into conflicts if
you happen to use the same registration name (although things will still break if
you picked the same JS function names). 
</p>
        <p>
  
</p>
        <p>
Here's what that might look like:
</p>
        <br />
        <div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new">
          <p style="margin: 0px">
            <span style="color: blue">if</span> (!Page.ClientScript.IsClientScriptBlockRegistered(<span style="color: blue">typeof</span>(<span style="color: #2b91af">WebmailAddressBookBizObj</span>), <span style="background: #e5e5e5">"ToggleCheck"</span>))
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: blue">string</span> js = <span style="color: #a31515">@"</span></p>
          <p style="margin: 0px">
            <span style="color: #a31515">                 
function ToggleCheck(node)</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                 
{</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                   
if (node.Checked)</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                       
node.UnCheck();</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                   
else</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                       
node.Check();</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                 
}"</span>;
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
    Page.ClientScript.RegisterClientScriptBlock(<span style="color: blue">typeof</span>(<span style="color: #2b91af">WebmailAddressBookBizObj</span>), <span style="background: #e5e5e5">"ToggleCheck"</span>,
js, <span style="color: blue">true</span>);
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=232647a7-8706-4a10-8a79-d08df3a3e6fa" />
      </body>
      <title>Javascript in User Controls</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,232647a7-8706-4a10-8a79-d08df3a3e6fa.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2007/10/27/JavascriptInUserControls.aspx</link>
      <pubDate>Sat, 27 Oct 2007 20:07:56 GMT</pubDate>
      <description>&lt;p&gt;
Imagine this scenario: You want to create a simple user control that you can use in
a few web pages. It incorporates a few JavaScript functions that change the UI slightly
during a mouse click; pretty standard stuff. The script isn't particularly useful
in other controls, so putting it into a common library doesn't make much sense. It
could be broken out into it's own library, which can at least be cached by a browser.
But that introduces another dependency in the hosting page - you have to remember
to include a reference to this JS library before things will work. The easiest thing
to do would be to just include the JS code inside the user control itself (I'm skipping
the option of embedding it as a resource; maybe another day). Including the code in
the control is pretty simple and seamless. Until you drop two instances of the same
control on page. What you'll find (like I did) is that your JS code is now rendered
one time for each control. That's not very cool. In fact, you run into this same issue
even if you decide to move the code into it's own library - you end up with more than
one reference to the library. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
A relatively simple way around all this is the ClientScriptManager class that is available
hanging off the Page object as ClientScript. It lets you register JS code to be rendered
into the main page. You can also check for the existence of the registered code (to
keep from registering it more than once, regardless of the number of controls on the
page). In my case, since I'm just embedding the code right in the page, there are
only two methods required for this: IsClientScriptBlockRegistered and RegisterClientScriptBlock. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The routines use the object type and the passed in name as a key; if you don't pass
it into IsClientScriptBlockRegistered (or the other variants) the routines will use
the Page's type. I'd suggest always passing in something besides the page type (for
example, the user control type). This will keep you from running into conflicts if
you happen to use the same registration name (although things will still break if
you picked the same JS function names). 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Here's what that might look like:
&lt;/p&gt;
&lt;br&gt;
&lt;div style="font-size: 10pt; background: white; color: black; font-family: consolas, courier new"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;if&lt;/span&gt; (!Page.ClientScript.IsClientScriptBlockRegistered(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;WebmailAddressBookBizObj&lt;/span&gt;), &lt;span style="background: #e5e5e5"&gt;"ToggleCheck"&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt; js = &lt;span style="color: #a31515"&gt;@"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
function ToggleCheck(node)&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if (node.Checked)&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
node.UnCheck();&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
node.Check();&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;WebmailAddressBookBizObj&lt;/span&gt;), &lt;span style="background: #e5e5e5"&gt;"ToggleCheck"&lt;/span&gt;,
js, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=232647a7-8706-4a10-8a79-d08df3a3e6fa" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,232647a7-8706-4a10-8a79-d08df3a3e6fa.aspx</comments>
      <category>ASP.NET</category>
      <category>Javascript</category>
    </item>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=fd07cdac-37b2-4e2d-8c1f-e534cd45bcea</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,fd07cdac-37b2-4e2d-8c1f-e534cd45bcea.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,fd07cdac-37b2-4e2d-8c1f-e534cd45bcea.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=fd07cdac-37b2-4e2d-8c1f-e534cd45bcea</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>Speeding up my ASP.NET app.</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,fd07cdac-37b2-4e2d-8c1f-e534cd45bcea.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2007/10/19/SpeedingUpMyASPNETApp.aspx</link>
      <pubDate>Fri, 19 Oct 2007 02:47:55 GMT</pubDate>
      <description>&lt;p&gt;
Once in a while I’ll get lucky and find a good sample of a solution to exactly the
problem I’m having. Last Friday was my day for this. I’ve been working on a portal-style
web application which includes security and logging on everything. I make some logging
calls from within my global.asax file. Running ASP.NET web apps under development
isn’t the fastest thing in the world and it’s always a bit of a problem to get a good
feel for it’s speed in production. However, I had a few pages which felt particularly
sluggish. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
I’ve played around with various .NET code profilers and while they’ve all been OK,
I haven’t committed to buying any of them. This time around I downloaded and installed
ANTS Profiler from Red Gate. Once limitation that most profilers seem to have is that
they require me to debug under IIS, which means I have to screw around with the code
a bit to get it ready for deployment before I can look into any performance issues
(although you can usually force them to fire up Cassini and profile it that way, it’s
usually not very intuitive). So it was kind of nice to be able to profile an app.
directly from ANTS. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
After a quick profile test it was pretty clear the problem was in the logging code.
There isn’t much going on here, grab some info. about the request (IP Address, page,
time, user ID, etc.) create a connection, then create and run the insert SQL code.
It was adding around 250ms to every page hit. I couldn’t do much to optimize this
code, but I thought I might be able to create a new thread to run this on so the user
wouldn’t have to wait while it ran. I found an excellent example of the exact issue
by Peter Bromberg on the Egghead Café site: &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/aa5ff306-16a1-4014-a51d-6ffde0894a0d/aspnet-request-logging-w.aspx"&gt;http://www.eggheadcafe.com/tutorials/aspnet/aa5ff306-16a1-4014-a51d-6ffde0894a0d/aspnet-request-logging-w.aspx&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
I didn’t need his connection or logging code, so I just snagged the thread class.
Then I created a delegate for the logging method call. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
My delegate code: 
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;&lt;?xml:namespace prefix = o /&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; color: blue; font-family: consolas"&gt;public&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt; &lt;span style="color: blue"&gt;delegate&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlExecDelegate&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt; command);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;Then I just wrapped
the call and passed in the SqlCommand variable I needed:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; color: #2b91af; font-family: consolas"&gt;ThreadUtil&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;.FireAndForget(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlExecDelegate&lt;/span&gt;(SqlExec),
Command);&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;Here’s the code I
grabbed from Peter – his article explains how it works in detail:&lt;b&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; color: blue; font-family: consolas"&gt;using&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt; System;&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; color: blue; font-family: consolas"&gt;using&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt; System.Runtime.CompilerServices;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; color: blue; font-family: consolas"&gt;namespace&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt; WirelessToyz.Utility&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;{&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="background: yellow"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="background: yellow"&gt; Downloaded
this class from:&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="background: yellow"&gt; &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/aa5ff306-16a1-4014-a51d-6ffde0894a0d/aspnet-request-logging-w.aspx"&gt;http://www.eggheadcafe.com/tutorials/aspnet/aa5ff306-16a1-4014-a51d-6ffde0894a0d/aspnet-request-logging-w.aspx&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="background: yellow"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ThreadUtil&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;AsyncCallback&lt;/span&gt; callback
= &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;AsyncCallback&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ThreadUtil&lt;/span&gt;.EndWrapperInvoke);&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegateWrapper&lt;/span&gt; wrapperInstance
= &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegateWrapper&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ThreadUtil&lt;/span&gt;.InvokeWrappedDelegate);&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;br&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; EndWrapperInvoke(&lt;span style="color: #2b91af"&gt;IAsyncResult&lt;/span&gt; ar)&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
wrapperInstance.EndInvoke(ar);&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
ar.AsyncWaitHandle.Close();&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;br&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; FireAndForget(&lt;span style="color: #2b91af"&gt;Delegate&lt;/span&gt; d, &lt;span style="color: blue"&gt;params&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt;[]
args)&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
wrapperInstance.BeginInvoke(d, args, callback, &lt;span style="color: blue"&gt;null&lt;/span&gt;);&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; InvokeWrappedDelegate(&lt;span style="color: #2b91af"&gt;Delegate&lt;/span&gt; d, &lt;span style="color: blue"&gt;object&lt;/span&gt;[]
args)&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
d.DynamicInvoke(args);&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;delegate&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegateWrapper&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Delegate&lt;/span&gt; d, &lt;span style="color: blue"&gt;object&lt;/span&gt;[]
args);&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Arial','sans-serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
I immediately saw a difference in my app. The pages felt a noticeable snappier. While
it still takes 250ms to run my logging code, I no longer have to make the user wait
for it. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Links&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/aa5ff306-16a1-4014-a51d-6ffde0894a0d/aspnet-request-logging-w.aspx"&gt;http://www.eggheadcafe.com/tutorials/aspnet/aa5ff306-16a1-4014-a51d-6ffde0894a0d/aspnet-request-logging-w.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=fd07cdac-37b2-4e2d-8c1f-e534cd45bcea" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,fd07cdac-37b2-4e2d-8c1f-e534cd45bcea.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.rcs-solutions.com/blog/Trackback.aspx?guid=d2bce8e6-6a4b-432d-ab48-47c3e3be83ec</trackback:ping>
      <pingback:server>http://www.rcs-solutions.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.rcs-solutions.com/blog/PermaLink,guid,d2bce8e6-6a4b-432d-ab48-47c3e3be83ec.aspx</pingback:target>
      <dc:creator>Paul Mrozowski</dc:creator>
      <wfw:comment>http://www.rcs-solutions.com/blog/CommentView,guid,d2bce8e6-6a4b-432d-ab48-47c3e3be83ec.aspx</wfw:comment>
      <wfw:commentRss>http://www.rcs-solutions.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=d2bce8e6-6a4b-432d-ab48-47c3e3be83ec</wfw:commentRss>
      <title>Accessing ASP.NET generated controls from Javascript</title>
      <guid isPermaLink="false">http://www.rcs-solutions.com/blog/PermaLink,guid,d2bce8e6-6a4b-432d-ab48-47c3e3be83ec.aspx</guid>
      <link>http://www.rcs-solutions.com/blog/2007/10/19/AccessingASPNETGeneratedControlsFromJavascript.aspx</link>
      <pubDate>Fri, 19 Oct 2007 02:36:20 GMT</pubDate>
      <description>&lt;p&gt;
This is one of those things that's really easy to do, but not particularly clear the
first time you run across it (well, it wasn't clear to me at least). There are times
when you need to access ASP.NET created controls from within your JavaScript code.
In the ASPX page you may have set the ID of a button control to "btnAdd". However,
when you run the page the control name gets mangled into something like ctl00_ContentPlaceHolder1_btnAdd.
In order to reference it in your JavaScript, you need that mangled name. To get it,
just embed something like this in your JavaScript code:
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;font face="Consol"&gt;&lt;font color="#0000ff"&gt;function&lt;/font&gt; DoSomething()&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;var&lt;/font&gt; addButton = document.getElementById('&amp;lt;%=
btnAdd.ClientID %&amp;gt;');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;if&lt;/font&gt; (addButton)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert('&amp;lt;%= btnAdd.ClientID %&amp;gt;');&lt;br&gt;
}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;font face="Consolas" size="2"&gt;&lt;span style="font-size: 10pt; font-family: consolas"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt; 
&lt;p&gt;
When the page is run, the ASP.NET eval engine will replace the ID with the correct
one.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.rcs-solutions.com/blog/aggbug.ashx?id=d2bce8e6-6a4b-432d-ab48-47c3e3be83ec" /&gt;</description>
      <comments>http://www.rcs-solutions.com/blog/CommentView,guid,d2bce8e6-6a4b-432d-ab48-47c3e3be83ec.aspx</comments>
      <category>ASP.NET</category>
      <category>Javascript</category>
    </item>
  </channel>
</rss>