Tuesday, 16 November 2010

User Control Cast Error

Came across an error I haven't had before using ASP .Net so thought I would share this with the world in case someone else had the same problem. After updating a page and copying it to the webserver when I came to look at it again I got this message:

Unable to cast object of type 'ASP.controls_student_ascx' to type 'Controls_Student'

In order to resolve this I had to clear my cache and then it worked fine.

Monday, 15 November 2010

Using javascript to create full screen windows in ASP .Net

My current role at DatabridgeMiS involves creating a web version of existing software, which can be tricky when trying to create the same functionality of popup windows that can be maximized to full screen.

When using the Ajax Control Toolkit I can use the ModalPopupExtender to create simple popup windows by setting the target to a panel that is invisible by default. I can set the panels width and height to control the size of my popup window.

However, I wanted to be able to achieve full width and height but I found using percentages of 100% for both and the body worked ok to some extent but looked confusing in places plus I wanted specific sizing for some items.

So I decided to create my own code to perform this action myself. I already had jquery attached to my page so I could use the document.Ready function to insert my code.

First I needed to find the width and height of the current viewport:

var viewportwidth;
var viewportheight;

if (typeof window.innerWidth != 'undefined') {
viewportwidth = window.innerWidth;
viewportheight = window.innerHeight;
}
else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
viewportheight = document.documentElement.clientHeight;
viewportwidth = document.documentElement.clientWidth;
}
else {
viewportheight = document.getElementsByTagName('body')[0].clientHeight;
viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
}

The code above performs different checks as different browsers use different methods of obtaining the viewport information and using only one method wouldn't work across the board. Next I used a jquery style function to find all 'panels' that I had put a class of 'fullscreen' on:

$('.fullscreen').each(function (i) {
$(this).width(viewportwidth);
$(this).height(viewportheight);
});

This then regardless of browser makes my popup full screen (although watch out for margin or padding settings that could enlarge it).

Then I simply used other jquery style functions to set elements height/width within the popup by simply subtracting the viewport settings. Have a play yourself and check it out on different browsers and screens, works brilliantly.

Future of Silverlight

On the 2nd December 2010 there will be an event in Redmond discussing silverlight, looking forward to what comes out of this after recent speculation that there would be no further development into silverlight.

Check out the details of the event at http://www.silverlight.net/news/events/firestarter/.

Sunday, 14 November 2010

title tags on images

The alt tag is always important when using images in case of blind users or the image couldn't be displayed. But don't forget to include a title tag as well because if you didn't know already FireFox doesn't display the tooltip from an alt tag only the title.
Published with Blogger-droid v1.6.3

Saturday, 13 November 2010

Using Linq to Split a List

Started using more Linq and had to use it recently for splitting a list of items.

Basically I had to create a treeview of items and I didn't want to have to keep loading the items from a stored procedure everytime I needed to add items to a node.

So here's what I did instead, I used one stored procedure to create one list:
List<NodeItem> list1 = New List<NodeItem>();
list1.LoadListItems(); // this function uses stored procedure and loads list

And then I filter this list into as many other ones as I need (or create a loop and create a list for each node I want to add to), by doing the following:
int NodeID = CurrentNodeID;
List<NodeItem> subNodes = New List<NodeItem>();
subNodes = list1.Where(n => n.LinkedID == NodeID).ToList();

This preserves list1 and saves me from running another data query, sorted.

Security Update for .Net

There is a recently discovered security vulnerability in .Net which is publicly known so make sure you get yourself updated. See here for more information.

Wednesday, 3 November 2010

Issue with using CSS check for iPad device width

Many people out there adopt the following way of using a stylesheet based on the max device width in order to use different styling for an iPad:

<link href="css/iPad.css" media="all and (max-device-width:1024px)" rel="stylesheet" type="text/css">

However after doing several browser checks in different resolutions for a site I had done just this on I found that if you were using a screen resolution of 1024x768 and the browser Google Chrome it uses the iPad css.

Therefore I had to change this strategy and instead now use the following code to get a better check on the device accessing the site:

<script type="text/javascript"> // <![CDATA[
if ((navigator.userAgent.indexOf('iPad') != -1)) {
document.write('<link href="css/iPad.css" media="all" rel="stylesheet" type="text/css">');
} // ]]></script>

Works perfectly now!!