Detecting the File Download Dialog in the Browser

by Victor 11. January 2013 19:22

I ran into a scenario in which I needed to know when a PDF file finished "rendering" to the browser. Actually, it was being served as an attachment. Either way, I needed to know when the client got the response back from the server. This stumped me for a while until I found this extremely useful block post describing a very elegant solution using a cookie. The gist of it is to create a token on the client side and send it to the server with your file request. I did it via the query string. On the server side, when the pdf is done, add a cookie with the value of the token. Back on the client side, poll for a cookie with the token. That's it! Check out the full explanation here.

Tags: ,

javascript | jQuery | Software Development | Web Development

Visual Studio Conditional Pre-Build Event

by Victor 9. January 2013 08:35

Say, for example, you want to execute a pre-build event if the current configuration is not Debug. Then you can do it like so:

 

if not '$(ConfigurationName)' == 'Debug' [YOUR PRE-BUILD STATEMENT]

Sorting with CanJS

by Victor 20. December 2012 18:06

I need to sort a list based on the selected value of a dropdown. I didn't find anything built in in CanJS. The can.Model.List does not have a sort method. Luckily, Curtis created a fiddle that does sorting. I adapted his code a bit and added the dropdown.

 

You can see the jsfiddle here

Tags: , ,

Web Development | javascript

"Invalid column name 'CreatedOn'" - Entity Framework Code First

by Victor 7. September 2012 16:53

I started getting this error in a production system a day ago but nothing had changed in that application. The application is a REST web service and hasn't been touched in months. BUT, I did deploy a different application that uses the same database. The new application uses Entity Framework 5.0 and the existing application uses 4.3. Also, the new application uses Code First Migrations so a new table called __MigrationHistory was automatically added. It turns out that the existing application had automatic migration enabled. So, all I had to do was turn that off using this line of code and redeploy the dll.

 

Database.SetInitializer<MyModelContext>(null);
 
I don't think automatic migrations should be enabled by default but I suppose some people would want it. Sometimes I think MS tries to put too many "automagic" features in their frameworks...

Tags: , ,

Entity Framework | Software Development | Web Development

Entity Framework 5.0!

by Victor 23. August 2012 01:33

Finally, Entity Framework 5.0 is out and it has a whole slew of new cool features. Well, they're cool in the sense that they're finally here but better late than never.

What’s New in EF5

EF 5 includes a number of new features and bug fixes to the EF4.3 release. Most of the new features are only available in applications targeting .NET 4.5, see the Compatibility section for more details.

  • Enum support allows you to have enum properties in your entity classes.
  • Spatial data types can now be exposed in your model using the DbGeography and DbGeometry types.
  • Performance enhancements - these are exciting. Essentially queries will be compiled automatically now. Read more here
  • Code First will now detect if you have LocalDb or SQL Express available for creating new databases. Visual Studio 2012 includes LocalDb, whereas Visual Studio 2010 includes SQL Express.
  • Code First will add tables to existing database if the target database doesn’t contain any of the tables from the model.

The EF Designer in Visual Studio 2012 also has some new features:

  • DbContext code generation for new models means that any new models created using the EF Designer will generate a derived DbContext and POCO classes by default. You can always revert to ObjectContext code generation if needed. Existing models will not automatically change to DbContext code generation.
  • Multiple-diagrams per model allows you to have several diagrams that visualize subsections of your overall model. Shapes on the design surface can also have coloring applied.
  • Table-Valued functions in an existing database can now be added to your model.
  • Batch import of stored procedures allows multiple stored procedures to be added to the model during model creation.

 

Here's a link to the getting started page of Entity Framework if you're new to it or want to see how to use features like Migrations.

Tags: , , , ,

Entity Framework | Software Development

Rotating text using CSS

by Victor 15. August 2012 21:18

This is a short style rule to help you rotate text in your html page using CSS.

 

.rotated-text {
    width:100px; height:20px; line-height:20px;
    -moz-transform: rotate(310deg);  /* FF3.5/3.6 */
    -o-transform: rotate(310deg);  /* Opera 10.5 */
    -webkit-transform: rotate(310deg);  /* Saf3.1+ */
    transform: rotate(310deg);  /* Newer browsers (incl IE9) */
    /* IE8+ - must be on one line, unfortunately */    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.6427876096865394, M12=0.766044443118978, M21=-0.766044443118978, M22=0.6427876096865394, SizingMethod='auto expand')";      /* IE6 and 7 */    filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.6427876096865394, M12=0.766044443118978,            M21=-0.766044443118978, M22=0.6427876096865394, SizingMethod='auto expand');   /*    * To make the transform-origin be the middle of    * the object.      */
    zoom:1;
    background:#ccc;
    font-weight:normal;
    margin:0 0 0 0;
}

Tags: , , , , , ,

ASP.NET | CSS | CSS3 | IE | Safari Development | Web Development

Get Date Part from a SQL DateTime

by Victor 9. August 2012 01:21

No matter how many times I used this, I always seem to forget. So, how DO you get just the date part from a DateTime object in SQL? Easy, like this:

 

DECLARE @someDate DATETIME
SET @someDate = '08/08/2012 10:15AM'
SELECT CONVERT(VARCHAR, @someDate, 101)

 

Try it, you'll see

Tags: , ,

SQL

Objects to querystring parameters serializing with jQuery

by Rod 18. June 2012 18:32

Did you know that you can serialize a javascript object to a parametized query string? I didn't!

But that ability came really useful when I was in need to create a "widget" of a page I maintain, which ultimately calls a web service, but right before doing so, creates an object.

I had in front of me a dilemma: Reuse the existing logic and manage it somehow or reinvent the wheel. Then I remembered something a professor once told me: don't reinvent the wheel. So, I took a look at the logic, and was about to write some logic to convert the intermediate object into a querystring when I thought "maybe this already exists" and what do you know? It does! That simplified the effort quite a bit. Using this to deserialize the query string handled things on the other side, and I was in business!

As always,stay programming my friends!

Rod

Tags:

Web Development | jQuery

Lessons learned when developing sites compatible with iPads #2

by Rod 11. June 2012 23:46

About a year ago I wrote a post with some "tips" on developing sites compatible with iPads.

Well, if you've following me, you might have noticed that I've been working on another "mobile" site.

These are some further "tips" and notes on working with mobile devices.

  • IOS Safari has a well known bugwhich causes the site to be zoomed in and be larger than the browser window what rotating the device. There are a couple of solutions for this:
    1. If you don't mind blocking users the ability of zooming in to the page, use simply use the metatag "<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">". This tag sets the viewport (the "window") to be initially zoomed in to be 1 and blocks all zooming abilities, preventing the rotation issue.
    2. If you want zoom abilities, then you can use javascript to disable the meta tag initialliy and enable it on the gesturestart event (see this) while still having the viewport zoom metatag enabled. I am attaching the script file I am using on the site.
  • Make sure you test in Android, iPhones, and iPads. Android's default browser and Chrome Beta zoom in/out and readjust the viewport properly on rotation! If you don't have an IOS device but have a Mac computer, you can get XCode and use the simulator (in my case, I created a blank project app and hit the go button). It's not the same as the actual device, but gives you an idea of how things are going.
  • If you have an Android device with ICS, you can install Chrome Beta and use the remote USB debugging feature; which enables you to edit the html and class, execute javascript with the console, etc; just as you would with a local html page in Google Chrome.
  • You can use css @media query to enable specific styling (for instance, change the fotn size when the device is in portrait or change the elements width when the device is a smaller screen like a phone VS a tablet). See this page for this an other "tips and considerations" on the responsive web, a new fad in web development which aims to create sites that can adapt to any screen size.

 

Well, that's all for now. I'll make sure to add more items as the dev work progresses.

As always, stay programming my friends!

Rod

iosSafariOrientationchangeFix.js (565.00 bytes)

Tags:

CSS3 | iOS | Mobile | Safari Development | Web Development

Mobile websites redirection with Asp.NET

by Rod 6. June 2012 22:07

My latest work involved creating the mobile version of some pages of a web application.

Once the pages conversion was relatively completed in the "~/Mobile/" path, I had to create the logic to redirect users to the mobile version of the "mobiled" pages automatically. This logic had to also permit users to navigate the desktop pages from their mobile devices with a "Desktop version" button.

The first task was the mobile device detection. I could have, of course, find "ios" and "android" in the user-agent, but that would not have been the "programmers way" and many devices (windows, blackberry, etc) would have circumvented detection, and we don't want that!

Some Google time pointed to the excellent open source MobileESP, whose ASP.Net implementations are already very nifty. Unfortunately I was not able to use the library as is for two reasons: The application was written in VB.Net and neither of the provided examples (base page and user control) could really be used in this environment.

What was a programmer supposed to do? Well, a previous programmer had created a common utility C# project, so the MobileESP code could be placed there. So, I extracted all the functional detection code and supporting data of "Sub-Classed Page Technique", placed it there, and I was halfway on my detection heaven! Here is the detection class I wrote.

From that point on, it was all a matter of implementing the logic to redirect to the correct pages when necessary in the existent base page; which I am pasting underneath

    ''' 
    ''' Determines if it is necesary to redirect to the mobile 
    ''' version of the current page and redirects if appropiate.
    ''' The check is done by checking if the current user has overriden 
    ''' the setting by clicking the "desktop version".
    ''' 
    ''' 
    Public Sub RedirectToMobileVersion()
        If Not Session("RedirectOverride") Is Nothing And Session("RedirectOverride") = "1" Then
            Exit Sub 'The user selected the desktop version
        End If

        Dim mobileDetector As MobileDeviceDetection = New MobileDeviceDetection(request)
       If mobileDetector.DetectMobileLong() Or mobileDetector.DetectTierTablet() Then
            Session("RedirectOverride") = Nothing 'Reset the redirect
            Dim url As String = String.Format("~/mobile{0}", Request.RawUrl.ToLower())
            Response.Redirect(url)
        End If
    End Sub

    ''' 
    ''' Redirects to the desktop version of the current page, setting the page override before doing so.
    ''' 
    ''' 
    Public Sub RedirectToDesktopVersion()
        Session("RedirectOverride") = "1" 'Set the redirect override
        Dim url As String = String.Format("~{0}", Request.RawUrl.ToLower().Replace("/mobile/", "/"))
        Response.Redirect(url)
    End Sub

The method RedirectToMobileVersion, which does what it's name indicates, is called on the page pre_init in all the pages that have a mobile version. As you can see this method's first action is to check the         Session("RedirectOverride") variable. This variable is set when the user navigates to the desktop version of the site on a mobile device and prevents the automatic redirection to leave him scratching his head with a big "huh?" face. You might have noticed that the detection uses both the "DetectMobileLong", which the documentation mentions should detect most devices, including iPads, and the "DetectTierTablet" method. Why? Well, in our testing we noticed that without calling out the tablet test specifically, iPad 2's were not being detected.

The method RedirectToDesktopVersion but before doing so, it sets the Session("RedirectOverride") variable (whose existence and function was explained above).

As you might have noticed, I am using the Request.RawUrl. Why you might ask? Well, that way the full URL, with query string parameters and all is used, and since the parameters are used the same way on the mobile and non mobile versions, this ensures smooth, flawless navigation between versions!

 

Hoping this is of any use to you,

Stay programming my friends!

Rod

MobileDeviceDetection.cs (40.34 kb)

Tags:

Powered by BlogEngine.NET 2.5.0.6

About Us

Wuji Touch is a software consulting firm based in Delray Beach, Florida. We specialize in Microsoft technologies, but we also have experience with Progress OpenEdge, iOS, and Android development. This is our blog. These are the tales of the pains and pleasures we experience daily in our journey through 1s and 0s.

Month List