Thursday, October 27, 2011

Big Bad Malware: One Helpful program.

I know several people now (including my wife) that have had their machines get infected with malware that is very hard to remove.  Microsoft recently released a tool that might be helpful.

Good luck!

Thursday, October 13, 2011

Free Windows Virtual Desktop Manager

I've been using an ancient virtual desktop manager called Yodem3D.  It works OK, but it is beginning to show its age lately.

So the 4SysOps blog had an article on a few to try (see comments too)-


I tried Windows Pager and it works OK.  Another mentioned is that looks like it might be better.  I'll give that one a shot later. If you know of any better ones please let me know in the comments! Thanks.

Tuesday, August 30, 2011

Regions in Visual Studio for Javascript

I can't believe I didn't find this earlier. Collapsible regions for Javascript in Visual Studio 2010-


Friday, August 19, 2011

.Net Generate QR Codes on the Fly

Pretty cool instructable tidbit on how to generate QR codes with .Net through an open source library.

For one off's there are a few sites where you can generate QR's. Here is a link to one-

And a way to decode QR codes online (if you don't have a smart phone app handy) -

Some Useful Bookmarklets

Here is a bookmarklet that allows you to check out what font's are used on a website-

Here is another that allows you to add live notes to a web page-

I use the Share on Twitter bookmarklet all the time-

Want to encrypt a message on Facebook or Twitter? Try this (Bookmarklet to the left of the page)

Thursday, August 18, 2011

HTML 5 Web Application Demo Worth Looking At

Dan Wahlin and a host of other .Net all stars created a demo HTML 5 web application that I suggest web developers look at (regardless of what server code you use on the back end, lots to be gleaned here). Here is a screen shot linked directly from Wahlin's blog-

Here is a list of the technologies used. There should be something to glean for everyone-

You can read about the application architecture and download it here-

Monday, August 01, 2011

Blizzard Goes User Based Micro Transactions

Very interesting...I like this model.  Diablo III will build it's revenue stream by taking a cut of micro transactions between players. The future is coming.

Thursday, July 21, 2011

The Canvas Tag

I'm taking my much belated first stabs at using the HTML 5 canvas tag from scratch, and I found a great site I thought I would share to get you going on the basics.

The basic elements of Canvas seem easy enough, putting it all together to make something unique and useful might be a different story.

And there are lots of great Canvas libraries out there, but I figured I'd start low level and work my way upward.

Wednesday, July 13, 2011

Remembering the COMBGuids

The new SQL Server 2005+ NewSequentialID() function is great because you can use GUIDs for primary key's without suffering the the query performance hit normally associated with using random values for primary keys due to ordering in tables. have to create these NewSequentialID's on the SQL side of things, which means that you have to pass them back to your web application, and sometimes that is problematic. It is much easier to create a GUID on the Web side of things before doing the insert, so that you have the key on the web side to access the just inserted data without having to have that key generated and then passed back to you.

For some of you what I'm saying will make absolutely no sense. For others, you see where I'm going. But with a technique known as COMBGuids, you can create sequential GUIDs for IDs on the web side and then pass them into your database.

Here is an implementation of COMBGuids that I've used in the past.

Tuesday, July 05, 2011

Using A ValidationSummary Control's ShowMessageBox (kinda) with Telerik Controls in Medium Trust

 I guess there is an issue with Validation Summaries and Telerik Controls.  If your site is running under Medium trust, you can't use the ShowMessageBox and instead you have to use the ShowSummary method.  I noticed this through off the styling of some of my controls once the error summary was rendered so I came up with a work around. Note be careful where you call this code else you will get an error, this worked for me using the FormView_ItemCommand.

ValidationSummary vs =
(ValidationSummary)MyFormView.Row.FindControl ( "myvalidationsummaryname" );
if ( vs != null )
  string sErr = vs.HeaderText  + "\\n";
  for ( int i = 0 ; i < this.Validators.Count ; i++ )
    if ( !this.Validators[ i ].IsValid )
      sErr += "* " + this.Validators[ i ].ErrorMessage + "\\n";
  myRadAjaxManager.ResponseScripts.Add ("alert('" + sErr + "');" );

That should get you going.

Tuesday, June 28, 2011

Populating a Telerik RadListBox with JSON on the Client Side

Ok, this is the poor man's way to do this. I'm actually not calling a web service to pull my jSON string back from the server, but rather a RadScriptManager, but this will get you going.

My approach. Note it assumed that you have a Telerik RadAjaxScriptManager on your page (or master page that you will need to access).

Step 1 Include the Following Namespace in Page Code Behind Class

using System.Web.Script.Serialization;

Step 2 Create a Class Object to be Serialized in the Page Code Behind Class

public class itm
   public string val { get; set; }
   public string txt { get; set; }

Step 3 Create a Serialization Method in the Page Code Behind Class

public string ToJSON ( object obj )
  JavaScriptSerializer serializer = new JavaScriptSerializer ();
  return serializer.Serialize ( obj );

Step 4 Create a Method in the Page Code Behind Class That Will Take Data, Populate a list of itms,Serialize that list into a jSON string, then call the RadAjaxManager's ResponseScripts.Add method to pass the jSON string to the client side.

A few notes here. One you could use AJAX to make a call to a web service to accomplish the same thing, for my example was just doing a basic test so I didn't bother. Also note that you will need to call this method somewhere (on a databind of a form view, Page_Load, whatever, inorder for the method to do anything). Note I'm doing a very lazy and inefficient way to get my data out of the database, I actually defined a sql datasource on my aspx page, and then reference it in the code behind. You probably will want to get your data another way...

void JSONListBoxItems ( hsRadListBox lst, SqlDataSource ds, string txt, string val )
  lst.Items.Clear ();
  List<itm> itms = new List<itm> ();
  if ( lst == null || ds == null || string.IsNullOrEmpty ( txt ) || string.IsNullOrEmpty ( val ) )
    DataView view = (DataView)ds.Select ( DataSourceSelectArguments.Empty );
    if ( view != null && view.ToTable () != null )
      DataTable table = view.ToTable ();
      for ( int i = 0 ; i< table.Rows.Count ; i++ )
       itm t = new itm ();
       t.txt = table.Rows[ i ][ txt ].ToString ();
       t.val = table.Rows[ i ][ val ].ToString ();
       itms.Add ( t );
   myRadAjaxManager.ResponseScripts.Add ("POPRadListBX('" + lst.ClientID.ToString () + "'," + ToJSON ( itms ) + ");" );

Step 5, Add the Following Javascript on the ASPX page.

function POPRadListBX(tid, js) {
        var lst = $find(tid);
        if (lst != null) {
          var zzz = lst.get_items();
          for (var i = 0; i < js.length; i++) {
            var item = new Telerik.Web.UI.RadListBoxItem();

Done. If I have time I'll circle back and make a downloadable example.

Monday, May 23, 2011

Friday, May 20, 2011

Web Forms Bloat

When .Net web forms first came out I hated them. Then I got used to them. Now MVC is out, and if I would have skipped web forms I would have loved MVC I think, but because there are some great web form tools out there I find looking to doing something similar in MVC to be not worth it, at least at this point for me. But, web forms do have their draw backs. Look at the line number of this error...

Now I'm hoping this is a faulty line number, but unfortunately I don't think it is. MS Ajax -> Telerik generated Javascript handlers -> 200 lines of Javascript on a page with 5 web grids = a bazillion lines of code I guess.

I bet with MVC this would be about 1/20th of the line number...interesting.

By the way, here is how to do a global Javascript catch if debugging tools aren't working for you-

 window.onerror=function(m, u, ln){
       alert('Error: '+m+'\nURL: '+u+'\nLine: '+ln)
       return true

More info here

Wednesday, May 11, 2011

Passing Client Side Dates to Server Side Vars With Telerik Rad Controls

Ok, sometimes you need to pass a client side datetime value from a Raddatetimepicker up to the server side for use. Sometimes with localization this can get kind of tricky, but Telerik introduced a new method to make this somewhat less painless.

in javascript
var dt = $telerik.findDatePicker("controlID", null);
  var dtValue = dt.get_selectedDate().format("yyyy/MM/dd");

This method will put your datetime value in a format that is SQL server friendly. Happy coding.

Sunday, February 20, 2011

Remembering Page Methods

Ok, I know ASP.Net web forms are all out of style now, even though if you are in a heavily data centric environment (one where you have grids upon grids upon grids) web forms still make the most sense in a lot of scenarios. So a lot of us are stuck with web forms and will be for as long as they are supported.

Anyway, one of the must under utilized capabilities in web form .Net apps are page methods. I sometimes forget the even exist in our jQuery / Ajax centered world. The preferred "best practice" method I'm sure would be to build a web service in WCF that you connect to through jQuery to do an Ajax call without a post back, but sometimes the quick and dirty approach that page methods offer is still useful.

So Zeeshan Umar has a good blog post about good old Page Methods here that the following code snip is based on.

I didn't add much to his example, so feel free to go right to his, but here is my own quick demo that I worked through just to remind myself that page methods still exists and how to use them based on Zeeshan's post.

The sample is just one aspx page with its code behind. This example demos submitting a registration form similar to what Zeeshan did-

The PageMethodsTest.aspx page (scroll bar at bottom, highlight all to copy/paste)

The PageMethodsTest.aspx.cs code behind.

Simple! Thanks for the reminder and quick code demo Zeeshan.

Bonus! Of course you can do all this with jQuery. One bonus using jQuery instead of Microsoft's ASP.Net AJAX is that you can leave the script manager off of your page. You can also easily call page methods ON OTHER PAGES (within the same project anyway), so then page methods really do become a poor man's quick and dirty alternative to WCF and ASMX for small task.

Here is an example HTML page that calls the above PageMethodTest.aspx RegUser method-


Here is a useful blog post from Encosia for more info on jQuery / page method calls-

Thursday, February 17, 2011

JavaScript: Available Window Height and Width

Ok, here is another junior varsity tip for using Javascript to get the true available window height and width. Note I stole this code from somewhere (though I tweaked it). I'd give credit if I remembered where I got it from, I don't.

function HSAvailWidth() {
  if (typeof window.innerWidth != 'undefined')
    return window.innerWidth;
  if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth !== 0)
    return document.documentElement.clientWidth;
  return document.getElementsByTagName('body')[0].clientWidth;
function HSAvailHeight() {
  if (typeof window.innerHeight != 'undefined')
    return window.innerHeight;
  if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientHeight != 'undefined' && document.documentElement.clientHeight !== 0)
    return document.documentElement.clientHeight;
  return document.getElementsByTagName('body')[0].clientHeight;

Or with jQuery...

$(window).height(); $(window).width();

Note: different browsers will have different available viewport height/widths because the browser tool bars very is size.

More here...

Tuesday, February 15, 2011

Very Cool jQuery Sorting/Suffling Plugin called Isotope

Check this jQuery plugin called Isotope out.

It has some pretty cool animation features, worth a look.

This Looks Interesting

A new Javascript/jQuery framework called the iX Framework looks pretty cool. It looks like it can do a lot (but not all) of what Telerik controls can do (though without the back end .Net integration). Might be work a look. $99 bucks for now.

Friday, February 04, 2011

Quick Tip: Generate Unique ID's in Javascript

Here is a little code snippet I use to create unique id's in Javascript when I'm dynamically adding dom elements.

function HSCreateID(apd) {
  return apd + '' + new Date().getTime();

More on the Date().getTime() function in Javascript-

Tuesday, January 25, 2011

Basic Polling Web jQuery Chat Example Using WebMatrix

*** Update: I had a bunch of junk comments left over from testing in the sdf database, some were kind of crude. I removed them from the source. Numbers 32:23 in action :) ***

Ok, here is a VERY rudimentary example to help you get web chat functionality going in a webmatrix site. I'm not getting fancy at all here, just three pages and a SQL CE database -> Chatpage.cshtml, pull.cshtml, push.cshtml. Essentially I've got my chat page that uses jQuery to poll a "pull" page every 1.5 seconds. I keep track of what data to return by using session time variables. And there is a simple jQuery post method to post new chat messages.

Note! This is just meant to help get you going, not meant to be production code (no SQL injection defense, might need to watch out for Chars in Javascript that might throw things off, not styled at all, yadda yadda yadda). But there is enough here to get you going. Also be warned that you need to test this with two different types of browsers if you are testing the code on your local machine (else a same browser just different windows will share the same session and messages will start disappearing).

Here is the [Source Code]. Or you can look at each page's source individually (scroll bars at the bottom of the code if it over flows).

Here is the ChatPage.cshtml

Here is the Push.cshtml page source

Here is the Pull.cshtml page source

Here is a picture of the database schema