Holiday Gifts for Web Developers

By | 2017-06-16T12:20:14+00:00 December 20th, 2013|Categories: Web Development|Tags: , , , |

Est. Reading Time: 2 minutes

Holiday WreathSeason’s greetings from Beacon! Today I’ve got a couple handy gifts that can help solve some tricky web development problems.

First lets unwrap how you can calculate line height on a client’s machine. This can be helpful when trying to truncate a block of text to not be more than say 3 lines tall. In order to do this across various browsers, devices, and zoom settings you need to see exactly how the font is rendered to the screen. To test this you need to sacrifice a chicken… sort of. See below:

You may have to add certain styling rules to the chicken if you want to measure a certain kind of font or what have you, but that’ll be different for each implementation. Now that you have that you can use whatever method you choose to measure individual line lengths to fit your container and still truncate properly, but one way I recommend is by initially truncating your string to the minimum character count that can fit in your area (like in a string with nothing but apostrophes) and then truncating by removing whole words until the element height is equal to 3 * lineHeight.

Lets see if there’s anything else to unwrap… Oh look here, have you ever wanted to post a javascript object (or array of objects) to your code behind and maybe pass the data along to the database? Did you know that by simply adding an empty asp control that uses postbacks that the page will come pre-equipped with a javascript function that allows you to do just that? Simply add this on your design file:

and suddenly you’ll notice that this function is defined on your page “__doPostBack” and with it you can post data directly to the back end. By calling the function with a target and an argument like this:

your data will be passed to this snippet on the back end:

In my example the javascript variable “myData” is a json array, and the type “MyDataObject” is a structure with matching properties so that the entire array can be quickly digested by the code. This also works in C#, though you’ll have to update the syntax.

I hope these gifts help you as you develop your own, hopefully festive, websites. Until our next festive update, Happy Holidays!

About the Author:

Beacon Buddy