<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Gregory Rubinstein</title><link>http://weblogs.asp.net/grblog/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Passing Parameter to Crystal Report</title><link>http://weblogs.asp.net/grblog/archive/2008/08/14/passing-parameter-to-crystal-report.aspx</link><pubDate>Thu, 14 Aug 2008 16:17:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6518155</guid><dc:creator>Gregory Rubinstein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/grblog/rsscomments.aspx?PostID=6518155</wfw:commentRss><comments>http://weblogs.asp.net/grblog/archive/2008/08/14/passing-parameter-to-crystal-report.aspx#comments</comments><description>&lt;p&gt;Recently, I was developing a pretty sophisticated Crystal Report that
included multiple sub-reports and used multiple stored procedures as
data sources. All of those stored procedures accepted the same
parameter, which made my life a little easier, since I only had to deal
with one parameter that I needed to pass to my Crystal Report.&lt;br&gt;&lt;br&gt;In
order for all sub-reports to be able to recognize the parameter, which
I am passing to the main report, I had to link all of my sub-reports to
the main report using that parameter.&lt;br&gt;&lt;br&gt;In order to link a sub-report to the main report, the following actions should be performed:&lt;br&gt;&lt;br&gt;To link a subreport to the data in the primary report&lt;/p&gt;&lt;ol&gt;&lt;li value="1"&gt;If you are creating a new subreport or importing an existing report  as a subreport, from the &lt;b class="desktop"&gt;Insert &lt;/b&gt;menu, click &lt;b&gt;Subreport&lt;/b&gt;. Choose or create a report and click the &lt;b class="desktop"&gt;Link &lt;/b&gt;tab.  &lt;p class="indent"&gt;- or -&lt;/p&gt; &lt;p&gt;If
you have already placed a subreport in the primary report, but did not
create a link at setup, navigate to the Subreport Links dialog box by
choosing &lt;b&gt;Subreport Links&lt;/b&gt; from the &lt;b&gt;Edit&lt;/b&gt; menu.&lt;/p&gt; &lt;p&gt;The Subreport Links dialog box appears.&lt;/p&gt; &lt;/li&gt;&lt;li value="2"&gt;Choose the subreport you want to link from the &lt;b&gt;For  subreport&lt;/b&gt; list (if it is not already selected).  &lt;/li&gt;&lt;li value="3"&gt;Select the field you want used as a link field in the primary  (containing) report from the &lt;b&gt;Available Fields&lt;/b&gt; list.  &lt;/li&gt;&lt;li value="4"&gt;Click the &amp;gt; arrow.  &lt;p&gt;The field is added to the "Field(s) to link to" list box, and is  now selected as a link field.&lt;/p&gt; &lt;/li&gt;&lt;li value="5"&gt;Repeat steps 3 and 4 for each additional link, as desired.  &lt;/li&gt;&lt;li value="6"&gt;Use the &lt;b&gt;Field link&lt;/b&gt; section (which will only  appear if you have selected a link field) to set up the link for each link  field:  &lt;ul type="disc"&gt;&lt;li&gt;Select the field you want linked to the primary report from the "Subreport  parameter field to use."  &lt;/li&gt;&lt;li&gt;Select the "Select data in subreport based on field" check box on and select  a field from the adjacent drop&lt;nobr&gt;-d&lt;/nobr&gt;own
list to organize the subreport data based on a specific field (this is
the quick equivalent of using the Select Expert). If nothing is
specified here, the subreport will adopt the organization of the
primary report. &lt;/li&gt;&lt;/ul&gt; &lt;/li&gt;&lt;li value="7"&gt;Click &lt;b&gt;OK&lt;/b&gt;. &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;When you run the report, the program will coordinate the  data in the primary report with the data in the subreport.&lt;/p&gt;Below is the code that I used to pass my parameter to the Crystal Report and then display it in PDF format to the end-user:&lt;br&gt;&lt;br&gt; &lt;font size="2"&gt;&lt;span style="font-size: 85%;"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Protected Sub&lt;/span&gt; Page_Load(&lt;span style="color: rgb(0, 0, 153);"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: rgb(0, 0, 153);"&gt;As&lt;/span&gt; Object, &lt;span style="color: rgb(0, 0, 153);"&gt;ByVal&lt;/span&gt; e &lt;span style="color: rgb(0, 0, 153);"&gt;As&lt;/span&gt; System.EventArgs) Handles &lt;span style="color: rgb(0, 0, 153);"&gt;Me&lt;/span&gt;.Load&lt;br&gt; &lt;blockquote&gt; GenerateReport(Session("EmpId"))&lt;/blockquote&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;End Sub&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Private Sub&lt;/span&gt; GenerateReport(&lt;span style="color: rgb(0, 0, 153);"&gt;ByVal&lt;/span&gt; EmpId &lt;span style="color: rgb(0, 0, 153);"&gt;As&lt;/span&gt; Integer)&lt;br&gt;  &lt;span style="color: rgb(0, 0, 153);"&gt; &lt;/span&gt;&lt;blockquote&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Dim&lt;/span&gt; theReport &lt;span style="color: rgb(0, 0, 153);"&gt;As New&lt;/span&gt; ReportDocument&lt;br&gt;  theReport.FileName = "C:\myProject\Reports\myReport.rpt"&lt;br&gt;  theReport.SetDatabaseLogon(PCON.APP.UserName, PCON.APP.Pass, PCON.APP.db_Server, PCON.APP.dbName)&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;'Set the required parameter for Crystal Report&lt;/span&gt;&lt;br&gt;theReport.SetParameterValue("@Id", EmpId)&lt;br&gt;&lt;br&gt;  &lt;span style="color: rgb(0, 102, 0);"&gt;'Now, present report in PDF format&lt;/span&gt;&lt;br&gt;  theReport.ExportToHttpResponse ( &lt;span style="font-size: 85%;"&gt;ExportFormatType.PortableDocFormat,&lt;/span&gt;&lt;span style="font-size: 85%;"&gt; Response,&lt;/span&gt;&lt;span style="font-size: 85%;"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt; False&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 85%;"&gt;, "ExportedReport")&lt;/span&gt;&lt;/blockquote&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;End Sub&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6518155" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx">VB.NET</category><category domain="http://weblogs.asp.net/grblog/archive/tags/Crystal+Reports/default.aspx">Crystal Reports</category><category domain="http://weblogs.asp.net/grblog/archive/tags/PDF/default.aspx">PDF</category></item><item><title>Crystal Reports with ASP.NET</title><link>http://weblogs.asp.net/grblog/archive/2008/05/09/crystal-reports-with-asp-net.aspx</link><pubDate>Sat, 10 May 2008 02:28:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6175493</guid><dc:creator>Gregory Rubinstein</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/grblog/rsscomments.aspx?PostID=6175493</wfw:commentRss><comments>http://weblogs.asp.net/grblog/archive/2008/05/09/crystal-reports-with-asp-net.aspx#comments</comments><description>&lt;p&gt;&lt;span style="font-family: arial; font-size: 9pt;"&gt;When it comes to
developing a report for an ASP.NET application, one might find that
there is very little information available on how it's done using
Crystal Reports.&lt;br&gt;&lt;br&gt;Visual Studio 2003 comes with a built-in
version of Crystal Reports (CR 9). Using that built-in version of
Crystal Reports might save you some money, since it's a part of VS
2003, however, from the Crystal Reports design prospective it is much
more convenient to use a stand-alone version of Crystal Reports.&lt;br&gt;&lt;br&gt;The
latest version of Crystal Reports at the time of writing this post is
Crystal Reports XI, which provides some new features, not available in
previous versions (see the &lt;a href="http://www.businessobjects.com/products/reporting/crystalreports/developer/default.asp" target="_blank"&gt;www.businessobjects.com&lt;/a&gt; website for more info), so in my last development I used that version of Crystal Reports.&lt;br&gt;&lt;br&gt;In order for the report to display as a webpage, VS 2003 provides CrystalReportViewer control. This is how it works:&lt;br&gt;&lt;br&gt;Instantiate the DataSet object&lt;br&gt;&lt;code&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Dim&lt;/span&gt; ds &lt;span style="color: rgb(0, 0, 153);"&gt;As New&lt;/span&gt; DataSet&lt;br&gt;&lt;br&gt;ds = GetDataForReport() &lt;span style="color: rgb(0, 102, 0);"&gt;'some method that retrieves data for the report&lt;/span&gt;&lt;br&gt;&lt;br&gt;Instantiate the ReportDocument object:&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Dim&lt;/span&gt; rpt &lt;span style="color: rgb(0, 0, 153);"&gt;As New&lt;/span&gt; ReportDocument&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;'set the ReportObject as the report you want to display&lt;/span&gt;&lt;br&gt;rpt = &lt;span style="color: rgb(0, 0, 153);"&gt;New&lt;/span&gt; CrystalReport1&lt;br&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;'Define the datasource of your report&lt;/span&gt;&lt;br&gt;rpt.SetDataSource(ds)&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;'define your report as a reportsource for the crystalreportviewer&lt;/span&gt;&lt;br&gt;&lt;strong&gt;CrystalReportViewer1.ReportSource = rpt&lt;/strong&gt;&lt;br&gt;&lt;/code&gt;&lt;br&gt;Below is C# version of this code:&lt;br&gt;&lt;code&gt;&lt;br&gt;DataSet ds = &lt;span style="color: rgb(0, 0, 153);"&gt;new &lt;/span&gt;DataSet();&lt;br&gt;ReportDocument rpt = &lt;span style="color: rgb(0, 0, 153);"&gt;new &lt;/span&gt;ReportDocument();&lt;br&gt;rpt = &lt;span style="color: rgb(0, 0, 153);"&gt;new &lt;/span&gt;CrystalReport1();&lt;br&gt;rpt.SetDataSource(ds);&lt;br&gt;&lt;strong&gt;CrystalReportViewer1.ReportSource = rpt;&lt;/strong&gt;&lt;br&gt;&lt;/code&gt;&lt;br&gt;&lt;br&gt;In order for this code to work, the following namespaces must be imported/used:&lt;br&gt;&lt;br&gt;CrystalDecisions.CrystalReports.Engine&lt;br&gt;CrystalDecisions.Shared&lt;br&gt;CrystalDecisions.Web.Design&lt;br&gt;&lt;br&gt;The following namespaces should be used only if you are planning to &lt;strong&gt;convert&lt;/strong&gt; the report into a &lt;strong&gt;PDF, Word, or Excel&lt;/strong&gt; format.&lt;br&gt;&lt;br&gt;CrystalDecisions.Shared.ExportDestinationType&lt;br&gt;CrystalDecisions.Shared.ExportFormatType&lt;br&gt;CrystalDecisions.Shared.ExportDestinationOptions&lt;/span&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6175493" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx">VB.NET</category><category domain="http://weblogs.asp.net/grblog/archive/tags/Web+Reporting/default.aspx">Web Reporting</category><category domain="http://weblogs.asp.net/grblog/archive/tags/Crystal+Reports/default.aspx">Crystal Reports</category></item><item><title>Converting ASP.NET to PDF</title><link>http://weblogs.asp.net/grblog/archive/2008/05/09/converting-asp-net-to-pdf.aspx</link><pubDate>Sat, 10 May 2008 02:21:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6175484</guid><dc:creator>Gregory Rubinstein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/grblog/rsscomments.aspx?PostID=6175484</wfw:commentRss><comments>http://weblogs.asp.net/grblog/archive/2008/05/09/converting-asp-net-to-pdf.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;span style="size: 9pt; font-family: Arial; color: rgb(0, 0, 0);"&gt;I
probably wouldn't be wrong if I said that most developers every now and
then are tasked to present specific data contained in a webpage as a
PDF document. There are two ways to do it:&lt;/span&gt; &lt;/p&gt;&lt;ol style="color: rgb(0, 0, 0); font-family: Arial; size: 9pt;"&gt;&lt;li&gt;using
the functionality of CrystalReportViewer's toolbar - this toolbar
provides a button, which does exactly that. However, to use this
approach you would have to actually display the crystal report on the
page.&lt;/li&gt;&lt;br&gt;&lt;li&gt;programmatically convert the Crystal Report object into a PDF document using the Crystal Reports API&lt;/li&gt;&lt;br&gt;&lt;/ol&gt;&lt;span style="size: 9pt; font-family: Arial; color: rgb(0, 0, 0);"&gt;Below is the code for the second approach:&lt;br&gt;&lt;br&gt;&lt;code style="font-size: 9pt; color: rgb(85, 85, 85);"&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Dim&lt;/span&gt; report &lt;span style="color: rgb(0, 0, 153);"&gt;As&lt;/span&gt; CrystalReport1 = &lt;span style="color: rgb(0, 0, 153);"&gt;New&lt;/span&gt; CrystalReport1&lt;br&gt;SqlDataAdapter1.Fill(DataSet11)&lt;br&gt;report.SetDataSource(DataSet11)&lt;br&gt;report.ExportToHttpResponse (ExportFormatType.PortableDocFormat, Response, False, "ExportedReport")&lt;/code&gt;&lt;/span&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6175484" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx">VB.NET</category><category domain="http://weblogs.asp.net/grblog/archive/tags/Web+Reporting/default.aspx">Web Reporting</category><category domain="http://weblogs.asp.net/grblog/archive/tags/Crystal+Reports/default.aspx">Crystal Reports</category><category domain="http://weblogs.asp.net/grblog/archive/tags/PDF/default.aspx">PDF</category><category domain="http://weblogs.asp.net/grblog/archive/tags/Convert+to+PDF/default.aspx">Convert to PDF</category></item><item><title>Remaining Characters Counter</title><link>http://weblogs.asp.net/grblog/archive/2008/04/10/remaining-characters-counter.aspx</link><pubDate>Fri, 11 Apr 2008 02:06:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6085156</guid><dc:creator>Gregory Rubinstein</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/grblog/rsscomments.aspx?PostID=6085156</wfw:commentRss><comments>http://weblogs.asp.net/grblog/archive/2008/04/10/remaining-characters-counter.aspx#comments</comments><description>&lt;p style="font-size: 9pt; font-family: arial;"&gt;Recently I was
developing a webform (asp.net) where the user could submit his
feedback, and one of the requirements was that the user should not
enter more than a set number of characters in his message, so I thought
it would be real nice for the end user to know how many more characters
he still can type until the maximum limit is reached.&lt;br&gt;&lt;br&gt;In order
to allow that functionality, I created a asp.net multiline textbox for
text input and an html readonly text field (for displaying number of
characters until the maximum).&lt;br&gt;&lt;br&gt;Then, I created a Javascript
function and called it every time the contents of the multiline textbox
changed (onKeyUp and onChange events).&lt;br&gt;&lt;br&gt;Below is the code:&lt;br&gt;&lt;br&gt;&amp;lt;html&amp;gt;&lt;br&gt;&amp;lt;head&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;script language="JavaScript"&amp;gt;&lt;/p&gt;function CountChars(text,long)&lt;br&gt;&lt;pre&gt;{&lt;br&gt;   var maxlength = new Number(long);&lt;br&gt;   var myLength = text.value.length;&lt;br&gt;   document.forms[0].Counter.value = maxlength - myLength;&lt;br&gt;   if (myLength &amp;gt; maxlength) {&lt;br&gt;      text.value = text.value.substring(0,maxlength);&lt;br&gt;   }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;&amp;lt;/script&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;/head&amp;gt;&lt;br&gt;&amp;lt;body&amp;gt;&lt;br&gt;&lt;br&gt;  &amp;lt;form id="Form1" runat="server"&amp;gt;&lt;br&gt;&lt;br&gt;    &amp;lt;asp:Textbox mode="multiline" id="txtMessage" runat="server" /&amp;gt;&amp;lt;br /&amp;gt;&lt;br&gt;&lt;br&gt;    &amp;lt;input type="text" name="Counter" readonly="readonly" /&amp;gt;&lt;br&gt;&lt;br&gt;  &amp;lt;/form&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;/body&amp;gt;&lt;br&gt;&amp;lt;/html&amp;gt;&lt;br&gt;&lt;br&gt;&lt;font color="#000099"&gt;        Protected Sub&lt;/font&gt; Page_Load(&lt;font color="#000099"&gt;ByVal&lt;/font&gt; sender &lt;font color="#000099"&gt;As&lt;/font&gt; Object, &lt;font color="#000099"&gt;ByVal&lt;/font&gt; e &lt;font color="#000099"&gt;As&lt;/font&gt; System.EventArgs) Handles &lt;font color="#000099"&gt;Me&lt;/font&gt;.Load&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Util.SetTextBoxProperties(txtMessage, &lt;font color="#000099"&gt;True&lt;/font&gt;)&lt;br&gt;&lt;font color="#000099"&gt;        End Sub&lt;/font&gt;&lt;br&gt;&lt;br&gt;Below is the SetTextBoxProperties method, which actually did the work:&lt;br&gt;&lt;br&gt;&lt;font color="#000099"&gt;&lt;span style="background-color: rgb(255, 255, 255);"&gt;Public Sub&lt;/span&gt;&lt;/font&gt; SetTextBoxProperties(&lt;font color="#000099"&gt;ByVal&lt;/font&gt; txt &lt;font color="#000099"&gt;As&lt;/font&gt; TextBox)&lt;br&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#000000"&gt;txt.Attributes.Add(&lt;/font&gt;&lt;font color="#660000"&gt;"onKeyUp"&lt;/font&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;font color="#660000"&gt;"CountChars(this,"&lt;/font&gt; &lt;font color="#000000"&gt;&amp;amp; txt.MaxLength &amp;amp;&lt;/font&gt; &lt;font color="#660000"&gt;")"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#000000"&gt;txt.Attributes.Add(&lt;/font&gt;&lt;font color="#660000"&gt;"onChange"&lt;/font&gt;&lt;font color="#000000"&gt;,&lt;/font&gt; &lt;font color="#660000"&gt;"CountChars(this,"&lt;/font&gt; &lt;font color="#000000"&gt;&amp;amp; txt.MaxLength &amp;amp;&lt;/font&gt; &lt;font color="#660000"&gt;")"&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;/span&gt;&lt;br&gt;&lt;font color="#000099"&gt;        End Sub&lt;/font&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6085156" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/grblog/archive/tags/useful+functions/default.aspx">useful functions</category><category domain="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx">VB.NET</category><category domain="http://weblogs.asp.net/grblog/archive/tags/utility+functions/default.aspx">utility functions</category><category domain="http://weblogs.asp.net/grblog/archive/tags/Javascript/default.aspx">Javascript</category></item><item><title>Active Control Marker</title><link>http://weblogs.asp.net/grblog/archive/2008/04/10/active-control-marker.aspx</link><pubDate>Thu, 10 Apr 2008 04:07:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6081124</guid><dc:creator>Gregory Rubinstein</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/grblog/rsscomments.aspx?PostID=6081124</wfw:commentRss><comments>http://weblogs.asp.net/grblog/archive/2008/04/10/active-control-marker.aspx#comments</comments><description>&lt;p&gt;Today, while working on my project, I recalled that some of the data entry pages in my project have a lot of textboxes, which may confuse the end-user once he starts entering information. My idea was to make the textbox that has focus visually different from the rest, so I came up with the following code snippet, that does the actual work:&lt;/p&gt;

&lt;p&gt;&lt;span style="color: blue;"&gt;Public Sub&lt;/span&gt; ShowActiveTextbox(&lt;span style="color: blue;"&gt;ByVal&lt;/span&gt; txt &lt;span style="color: blue;"&gt;As&lt;/span&gt; TextBox)&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; txt.Attributes.Add(&lt;span style="color: brown;"&gt;"onfocus", "this.className='class1'"&lt;/span&gt;) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; txt.Attributes.Add(&lt;span style="color: brown;"&gt;"onblur", "this.className='class2'"&lt;/span&gt;) &lt;/p&gt;

&lt;p&gt;&lt;span style="color: blue;"&gt;End Sub&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;This code would work just fine if I had only one or two Textboxes on my page. However, some of the pages may contain a dozen of those textboxes, so I came up with another useful method:&lt;/p&gt;

&lt;p&gt;&lt;span style="color: blue;"&gt;Public Sub&lt;/span&gt; ShowActiveTextbox(&lt;span style="color: blue;"&gt;ByVal&lt;/span&gt; col &lt;span style="color: blue;"&gt;As&lt;/span&gt; ControlCollection)&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;For Each&lt;/span&gt; Ctl &lt;span style="color: blue;"&gt;As&lt;/span&gt; Control &lt;span style="color: blue;"&gt;In&lt;/span&gt; col&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;  &lt;span style="color: blue;"&gt;If&lt;/span&gt; Ctl.GetType().Name = &lt;span style="color: brown;"&gt;"Textbox"&lt;/span&gt; &lt;font color="#0000cc"&gt;Then&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;span style="color: blue;"&gt;Call&lt;/span&gt; ShowActiveTextbox(Ctl)&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;Else&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;  &lt;font color="#006633"&gt;'Handle TextBoxes contained in container controls, such as panel&lt;/font&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; If&lt;/font&gt; ctl.Controls.Count &amp;gt; 0 &lt;font color="#0000cc"&gt;Then&lt;/font&gt;&lt;/p&gt;

&lt;p&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;Call&lt;/span&gt; ShowActiveTextBox(ctl.Controls)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000cc"&gt;End If&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;  &lt;span style="color: blue;"&gt;End If&lt;/span&gt;&lt;/p&gt;

&lt;span style="color: blue;"&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;br&gt;&amp;nbsp;End Sub&lt;/p&gt;
&lt;/span&gt;

&lt;p&gt;&amp;nbsp;Now we have a method that will handle any number of controls on a specific page and will apply the onFocus and onBlur event handlers to all Textboxes on that page.&lt;br&gt;
&lt;/p&gt;

&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6081124" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/grblog/archive/tags/useful+functions/default.aspx">useful functions</category><category domain="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx">VB.NET</category><category domain="http://weblogs.asp.net/grblog/archive/tags/utility+functions/default.aspx">utility functions</category></item></channel></rss>