INCLUDE_DATA

Archive for the ‘programming’ Category

Forcing a user to read (or scroll through) all text before accepting terms

December 10th, 2009

If you’ve used a computer before you’ve undoubtedly scrolled through and agreed to some sort of agreement.  Most likely it was some sort of software license agreement that you didn’t read about some website you were signing up on or an application that you were installing.

Maybe, if you’ve installed enough software or been on enough websites you’ve come across an instance where they actually forced you to scroll all the way down to the bottom of the text before you were able to click “I Agree” or whatever acknowledgment they wanted you to use.

Well I was recently faced with creating this exact situation in a web application and ended up using jQuery to accomplish this in my ASP.NET application.  For my particular situation I ended up putting my content inside a scrollable div.  This can easily be done by using a textbox if you wanted without much effort.

Basically, here’s what you’ll need.

  1. Reference jQuery (I’m not going to go into that, you can easily find that out here)
  2. Put a DIV on your page containing your text that needs to scroll (obviously you’re putting more than a few sentences or you wouldn’t be in this boat)
  3. Put a button on your page that, once enabled, will log the user’s acceptance and redirect them accordingly
  4. Some simple JavaScript to tie the DIV’s scrolling event to your button

Here’s our DIV:

<div style="width: 400px; height: 400px; overflow: auto; id="Terms">
<p>Lots of text to read.</p>
<p>Lots more text to read</p>
</div>

Here’s our button:

<asp:Button ID="ContinueButton" runat="server" Text="Continue" />

Here’s our JavaScript:

<head runat="server">
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript">
     $(document).ready(function() {
 
          // Initially disable the button
          $("#ContinueButton").attr("disabled", "disabled");
 
          // Map the function below to the scroll event of our Terms DIV
          $("#Terms").scroll(function() {
               if ($("#Terms").AtEnd()) {
                    // Enable the button once we reach the end of the DIV
                    $("#ContinueButton").removeAttr("disabled");
               }
           });
     });
 
     $.fn.AtEnd = function() {
         return this[0].scrollTop + this.height() >= this[0].scrollHeight;
     } 
</script>
</head>

And that’s it. This code is light weight and works in IE, Firefox, Chrome and Safari. Have any feedback or suggestions on how to make it better? Let me know.

CMD HTTP Request – command line HTTP request utility

December 9th, 2009

More and more I find that I need to setup some kind of job or scheduled task to accomplish something in .NET on a reoccurring basis.  Typically in the past I’ve written Windows Services to accomplish this.  While effective, these definitely take longer to write and are harder to debug than say a simple ASP.NET page.  What I’ve done lately is started to move these non-critical, non-security sensitive processes into ASP.NET pages that can be called on a specific schedule via Windows Task Scheduler.

When I started moving this way I realized that I wanted to find a small utility that I could run from a command line to initial a web page request.  It had to be something I could run from a scheduled task and something that I could use to save or log the results.  After doing my due diligence Googling I realized there wasn’t such a utility that I could easily run from within Windows without installing all kinds of libraries and non-Windows based tools.  So, like any good programmer, I made my own.  Enter CMD HTTP Request.

As I said, this utility is small, light weight and runs on Windows via the .NET Framework.  You don’t need any special commercial programs to run it and it will even check your pages for keywords you specify and save the request’s results to disk as a HTML file.  This, essentially, is your log of what happened during that request on that date and time.

I won’t go into too much more detail here.  I think you get the main idea.  You can  download the source code or executable from the project page on Codeplex and learn more about it.  As always, feel free to leave me any feedback or suggestions either here or via the project page on Codeplex.

CMD Email v2.0 released

November 14th, 2009

CMD Email, the email command line utility I developed (originally discussed here) has been updated to version 2.0.

Here are new features for v2.0:

  • Updated to target .NET 3.5 Framework
  • Added support for message body being loaded from a file
  • Added support for multiple file attachments
  • Added support for logging to the Windows Application Event Log

You can download the latest runtime or source from the project page on CodePlex.

Dynamically re-size an iFrame’s height across browsers

July 8th, 2009

A while back I had a need to dynamically re-size an iFrame’s height and found a solution using a jQuery plug-in called autoHeight.  What I later found was that this solution provided poor results with Internet explorer when my iFrame’s contents were fairly large and frequently changing (i.e. via navigation inside the iFrame).

It took quite a bit of tinkering but I was able to come up with a solution that works (and works well) in IE, Firefox, Safari and Chrome.  It still uses jQuery but doesn’t depend on a plug-in.  Here’s the code in case you’re looking for the same thing:

First, the iFrame…

<iframe src="Page1.htm" id="MyFrame" 
frameborder="0" marginheight="0" marginwidth="0" 
width="800px" height="100px" scrolling="no"></iframe>

Next, the JavaScript to resize it…

<script type="text/javascript">
 
     function sizeFrame() {
          jQuery("#MyFrame", top.document).css({ height: 0 });
          var heightDiv = jQuery("#MyFrame", top.document).contents().find('body').attr('scrollHeight');
          jQuery("#MyFrame", top.document).css({ height: heightDiv });
     }
 
     jQuery(function() {
          sizeFrame();
          jQuery("#MyFrame").load(sizeFrame);            
     });
 
</script>

This line is needed to initially initialize the height so that it works in Safari and Chrome. Without this line the window will never shrink to fit smaller content, it will just retain the last biggest height.

jQuery("#MyFrame", top.document).css({ height: 0 });

Visual Studio 2008 is a piece of shit!

July 3rd, 2009

It’s been one of those weeks :(

visual-studio-wait

It should be noted that I was able to take a screen shot, upload it to Wordpress and make this blog post before that message went away and I was able to interact with Visual Studio.NET again!

July 2009 Baltimore SQL Server Users Group Meeting

July 2nd, 2009

Passing along the Baltimore SQL Server Users Group July 2009 Meeting Announcement.  I’m considering attending since we use Reporting Services and SQL Server 2008 here at work.  Here’s the information in case you may be interested in attending.  Don’t forget to RSVP via email as noted below.

General Meeting Information

Presentation Information

  • Title: SQL Server Reporting Services Report Builder 2.0
  • Speaker: Craig Guyer of Microsoft
  • Abstract: Authoring reports for SQL Server Reporting Services is even easier than before using the new stand-alone application Report Builder 2.0 (RB2). In this session we will walk through creating some basic reports, show how RB2 fits in with other report authoring applications, and discuss other new report authoring features in SQL Server 2008.

MS Reporting Services Report Viewer Control printing errors with IE8 and Vista

May 29th, 2009

We use SQL Server 2008’s Reporting Services for all of our site’s reports here at work.  Along with that we also use Microsoft’s Report Viewer control which gives you the ability to serve up the RDL files that are stored in SQL Server.  One of the features that the control offers is the ability to print your reports.  To accomplsih this it uses Active-X, which we all know can be funky and a hassle to troubleshoot when it’s not working properly.

When we released our new system back in February we got most of our users printing with minimal support.  We encouraged all of them to upgrade to IE 7 (many were still using IE6) which did fine with the control.  Shortly after our launch Microsoft started rolling out IE8 and our users slowly started upgrading.

That’s when we found many of them having issues printing.  As you’ll see in this screen shot, they would simply get a generic error when clicking the print button, even after successfully installing the print control.  As a work around we were having folks export to PDF and then print from there.  Obviously this wasn’t an ideal solution and we started troubleshooting to figure out what the problem was.

rs-report-error

After doing some testing on our end on virtual machines we were able to reproduce the problem and narrowed it down to Windows Vista running IE8.  Since we weren’t able to resolve the problem on our virtual machine configuration with anything we tried we eventually opened a support ticket with Microsoft.

After some support calls with Microsoft they informed us that in order for this to work properly you have to add the site that’s using the report viewer control as a trusted site if you’re using Internet Explorer 8 and Windows Vista. We thought this was odd because we definitely had tried this on our virtual machine setup and didn’t have any luck.

What we found out on our own later was that as that this solution does not seem to help if you originally started out with a Beta or RC (Release Candidate) copy of IE8 that had been upgraded to the final release.  That was the scenario we had on our virtual machine that we were using to test IE8 and even the trusted site fix didn’t help in that scenario.

So, if you are having this problem and you’re using a clean install of IE8 or an upgrade to the final release of IE8 from a previous version adding the trusted site to fix this problem is easy.

Just open up IE and click Tools > Internet Options and follow the steps shown here in the screen shot to add your site as a trusted site:

trusted-sites

Restart your browser and you’re in business.

Now if they could only get away from Active-X so our users that decide not to use IE can print.

Baltimore SQL Server Users Group 5/4

April 23rd, 2009

Last night at the Frederick .NET user group Jeremy Kadlec of Edgewood Solutions (one of the founders of the Baltimore SQL Server Users group, was a speaker.  I didn’t realize that this group met so close to where I work here in Columbia.  After checking out the website I was excited to learn that they met on the first Monday of the month.  Tuesdays and Thursdays, which seem to be popular days for most of the other user groups in the area are not an option for me since I handle the kids those nights while my wife tutors.

So, I’ll be checking out the group for the first time on Monday May 4th.

Presenter: Jack Richins of Microsoft

Title – SQL Server 2008 Security

Abstract – SQL Server 2008 introduced three new security features – Transparent Data Encryption, Enterprise Key Management, and SQL Audit. With increased concerns about privacy and data thefts, security remains a “must have” business feature even with constrained budgets. Come learn how to use these features to better secure your database applications and met business compliance regulations.

Learn how to:
* Protect your data at rest
* Use 3rd party key management systems to encrypt data in SQL Server with keys stored outside of SQL Server
* Keep an audit record of access to sensitive data without tanking your performance

Learn more about their meeting schedule here.  If you’re in the area and are interested in the topic, stop by!

Going for MCTS certification on Visual Studio 2008

April 23rd, 2009

I have been dragging my feet for the past few years in regards to finishing up my Microsoft development certification.  Actually, the last test I took was 70-229 Designing and Implementing Databases with Microsoft SQL Server 2000 Enterprise Edition back on Dec 08, 2003.  WOW, I had no idea it was that long until I just looked it up.

Anyway, what finally got me to get moving was a great voucer/coupon I got via email from Prometric, the testing company I used last time.  Not sure if it’s specific to me because I’m already a MCP (yes, I passed that test from years ago) or not but I’ll share it just in case it does work for others…

…Improving and validating your technical skills can help.

That is why Prometric is providing a limited offer to the first 4,000 individuals to help get your Microsoft Certified Professional status current or achieve an additional certification.

Offer available for customers who have taken their last certification exam prior to January 1, 2007.

Use this promo code ‘MCPBACK’ and get a $25 USD Certification (Normally priced at $125 USD). This offer is valid for any exam in the MCTS/MCPD/MCITP track. Does not include Microsoft Office or Windows end-user (non-IT) focused exams.

Go to: www.Prometric.com/microsoft to sign-up for your next exam.

But you better hurry!
You must take your exam by June 30, 2009.

Offer valid in US and Canada only.

My plan is to obtain the MCTS: .NET Framework 3.5, ASP.NET Applications certification related to Visual Studio 2008.  What I’m going to do is take the C# test rather than VB.NET, which is what I mainly use here at work.  I can work in C# and have written a few things in it, but my main language since I’ve been working in .NET has been VB.NET.

I figure this will be a good way to become more familiar with C# and will force me to learn the language.  Once you’ve been working with .NET for a while and looking through code samples on Google you’ll quickly realize that the majority of the code samples out there are done in C#.  So, as you can imagine, converting those to VB.NET can be frustrating after a while.

So, we’ll see how it goes.  I only spent $25 to book the test and another $44 to upgrade my copy of MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework Application Development Foundation to the second edition.  I picked up the first edition a year or two ago when I first decided I wanted to get the MCTS and only got about 1/2 way through it.

My test is set for June 17, wish me luck!

FredNUG tonight

April 22nd, 2009

I’ll be attending the Frederick .NET user group tonight.  Tonight’s topics will be SQL Server Performance and Coding for Fun and Profit.  More information can be found here.