<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Gregory Rubinstein</title><subtitle type="html" /><id>http://weblogs.asp.net/grblog/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/grblog/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/grblog/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2008-04-10T00:07:00Z</updated><entry><title>Crystal Reports with ASP.NET</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/grblog/archive/2008/05/09/crystal-reports-with-asp-net.aspx" /><id>http://weblogs.asp.net/grblog/archive/2008/05/09/crystal-reports-with-asp-net.aspx</id><published>2008-05-10T02:28:00Z</published><updated>2008-05-10T02:28:00Z</updated><content type="html">&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;</content><author><name>grigorythegreat</name><uri>http://weblogs.asp.net/members/grigorythegreat.aspx</uri></author><category term="asp.net" scheme="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx" /><category term="VB.NET" scheme="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx" /><category term="Web Reporting" scheme="http://weblogs.asp.net/grblog/archive/tags/Web+Reporting/default.aspx" /><category term="Crystal Reports" scheme="http://weblogs.asp.net/grblog/archive/tags/Crystal+Reports/default.aspx" /></entry><entry><title>Converting ASP.NET to PDF</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/grblog/archive/2008/05/09/converting-asp-net-to-pdf.aspx" /><id>http://weblogs.asp.net/grblog/archive/2008/05/09/converting-asp-net-to-pdf.aspx</id><published>2008-05-10T02:21:00Z</published><updated>2008-05-10T02:21:00Z</updated><content type="html">&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;</content><author><name>grigorythegreat</name><uri>http://weblogs.asp.net/members/grigorythegreat.aspx</uri></author><category term="asp.net" scheme="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx" /><category term="VB.NET" scheme="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx" /><category term="Web Reporting" scheme="http://weblogs.asp.net/grblog/archive/tags/Web+Reporting/default.aspx" /><category term="Crystal Reports" scheme="http://weblogs.asp.net/grblog/archive/tags/Crystal+Reports/default.aspx" /><category term="PDF" scheme="http://weblogs.asp.net/grblog/archive/tags/PDF/default.aspx" /><category term="Convert to PDF" scheme="http://weblogs.asp.net/grblog/archive/tags/Convert+to+PDF/default.aspx" /></entry><entry><title>Remaining Characters Counter</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/grblog/archive/2008/04/10/remaining-characters-counter.aspx" /><id>http://weblogs.asp.net/grblog/archive/2008/04/10/remaining-characters-counter.aspx</id><published>2008-04-11T02:06:00Z</published><updated>2008-04-11T02:06:00Z</updated><content type="html">&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;</content><author><name>grigorythegreat</name><uri>http://weblogs.asp.net/members/grigorythegreat.aspx</uri></author><category term="useful functions" scheme="http://weblogs.asp.net/grblog/archive/tags/useful+functions/default.aspx" /><category term="asp.net" scheme="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx" /><category term="VB.NET" scheme="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx" /><category term="utility functions" scheme="http://weblogs.asp.net/grblog/archive/tags/utility+functions/default.aspx" /><category term="Javascript" scheme="http://weblogs.asp.net/grblog/archive/tags/Javascript/default.aspx" /></entry><entry><title>Active Control Marker</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/grblog/archive/2008/04/10/active-control-marker.aspx" /><id>http://weblogs.asp.net/grblog/archive/2008/04/10/active-control-marker.aspx</id><published>2008-04-10T04:07:00Z</published><updated>2008-04-10T04:07:00Z</updated><content type="html">&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;</content><author><name>grigorythegreat</name><uri>http://weblogs.asp.net/members/grigorythegreat.aspx</uri></author><category term="useful functions" scheme="http://weblogs.asp.net/grblog/archive/tags/useful+functions/default.aspx" /><category term="asp.net" scheme="http://weblogs.asp.net/grblog/archive/tags/asp.net/default.aspx" /><category term="VB.NET" scheme="http://weblogs.asp.net/grblog/archive/tags/VB.NET/default.aspx" /><category term="utility functions" scheme="http://weblogs.asp.net/grblog/archive/tags/utility+functions/default.aspx" /></entry></feed>