INCLUDE_DATA

Archive for December, 2009

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.