How to Reduce the Margin/Padding around a CheckBox

I was creating a HTML form recently which involved a lot of checkboxes. The client needed the space between the checkbox and the text to be reduced. An obvious choice was to reduce the Margin and Padding around the checkboxes, however this did not work around different browsers. I finally emulated the effect using the width of the checkbox. Here’s how:

<html xmlns="http://www.w3.org/1999/xhtml">

<
head>
<
meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<
title>Reduce Padding</title>
<
style type="text/css">
div
{
border:solid 1px;
}
input.chk {
width: 10px;
margin:0;
}
</style>
</
head>

<
body>
<
div>
<
input id="Checkbox1" type="checkbox"/> One <br />
<
input id="Checkbox2" type="checkbox"/> Two <br />
<
input id="Checkbox3" type="checkbox" class="chk"/> Three <br />
<
input id="Checkbox4" type="checkbox" class="chk"/> Four
</div>
</
body>

</
html>

Output

image

Check out the first two checkboxes which have the default width, margin and padding. Now check out the last two checkboxes which have a reduced width, margin and padding.

This tip should save time for those who have been trying to do the same using the margin and padding properties. The trick is to also set the width property.

Creating a Bouncing DIV / Panel using jQuery

Lately, I have been doing some crazy UI stuff with jQuery and posting them over here and here. I was recently experimenting with animating the HTML Div’s/ ASP.NET Panels. The animations by default work on the height property and animates it downwards. I wanted to reverse the behavior, creating a bouncing effect from bottom to top. Here’s how i did it using jQuery:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head >
<
title>Bouncing DIV'S</title>
<
style type='text/css'>
.parent
{
position:relative;
height:500px;
width:100%;
border:1px solid;
}
.myDiv
{
position:absolute;
top:50%;
height:250px;
width: 50%;
margin-top:-125px;
margin-left:250px;
border:1px solid;
}

</style>
<
script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>

<
script type="text/javascript">
$(document).ready(function() {
$('.myDiv').hover(
function() {
$(this).animate({ top: '25%', height: '300px' }, 'slow');
},
function() {
$(this).animate({ top: '50%', height: '250px' }, 'slow');
});
});

</script>
</
head>
<
body>
<
form id="form1" >
<
div class="parent">
<
div class="myDiv">
</
div>
</
div>
</
form>
</
body>
</
html>

You can even use ASP.NET Panels instead of plain HTML DIV’s. Just replace the div’s with this markup


<asp:Panel ID="Panel1" runat="server" CssClass="parent">
<
asp:Panel ID="Panel2" runat="server" CssClass="myDiv">
</
asp:Panel>
</
asp:Panel>

You can view a Live demo of the Bouncing DIV over here. Just hover your mouse on the inner div and watch it bouncing.

Live Demo: http://www.dotnetcurry.com/Demos/jQueryBouncingDiv/Bounce.htm

Robotics Development Studio 2008 R2‏ Released

Microsoft announced the availability of Microsoft Robotics Developer Studio (RDS) 2008 R2.

As given on the Microsoft site,

Robotic Development Studio is a software development kit for creating robotics applications. It provides the basic infrastructure for building applications that are highly concurrent and allows them to be distributed across multiple computers in a network by using a message-passing framework. At the lowest level, programmers can write the equivalent of device drivers for sensors and actuators. However, a primary function of RDS is to orchestrate higher-level services so that they can interact with each other to implement complex behaviors.

Additional information about the release can be found over here:

Microsoft Robotics Developer Studio 2008 R2 Express Edition

Microsoft Robotics Developer Studio Home Page

Video on Channel 9 discussing new features

Robotics Developer Studio 2008 R2 and CCR & DSS Toolkit 2008 R2 Release Notes

Free E-Books from Microsoft Press

Check out these Free E-Books offered by Microsoft Press to celebrate their 25th anniversary!

Programming for Unified Communications with Microsoft Office Communications Server 2007 R2

Step-by-step programming scenarios show you how to deliver high-quality VoIP, presence, click-to-communicate, and contextual collaboration across the enterprise and across time zones.

Microsoft Office Communications Server 2007 R2 Resource Kit

Get the definitive resource for deploying, configuring, and supporting Office Communications Server 2007—now fully updated

Get more details about the books over here http://blogs.msdn.com/microsoft_press/archive/2009/06/16/free-e-books-all-ocs-all-the-time.aspx

Changing Image Opacity on MouseOver using jQuery

Have you played the online memory game where an image appears when you hover over it and disappears on hover out. You have 20 images to view in 30 seconds and the one remembering the most wins. Well I wont be creating the game over here, but I will show you how to change the opacity of the image when the mouse if hovered over it.

<html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<
title></title>
<
style type="text/css">
img
{
opacity:0.0;
filter:alpha(opacity=0);
}
</style>
<
script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>

<
script type="text/javascript">
$(document).ready(function() {
$('img').each(function() {
$(this).hover(function() {
$(this).stop().animate({ opacity: 1.0 }, 500);
},
function() {
$(this).stop().animate({ opacity: 0.0 }, 500);
});
});
});

</script>
</
head>
<
body>
<
form id="form1" runat="server">
<
div>
<
img alt="" src="images/emo.jpg" />
<
img alt="" src="images/icon068.gif" />
<
img alt="" src="images/icon260.jpg" />
</
div>
</
form>

</
body>
</
html>

Initially, all the images have an opacity of 0 – being completely transparent. When the mouse hovers over each one of them, the image is displayed, one at a time. The image disappears when the mouse hovers out. You can even use this technique to create a cool UI effect in your applications.

image

Filter Image Types Using jQuery

I came across an interesting requirement recently. The application was similar to an image viewer and allowed users to filter out different image types on the click on a button. For eg: If the page contained .jpeg, .gif and .png’s, you could on the click on a button, hide the images with the .gif extension. Here’s how I solved the requirement:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<
title></title>

<
script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<
script type="text/javascript">
$(document).ready(function() {
$('#btn').click(function() {
$('img').each(function() {
if ($(this).is('[src$=.gif],[src$=.Gif],[src$=.GIF]'))
$(this).hide();
});
});
});

</script>
</
head>
<
body>
<
form id="form1" runat="server">
<
div>
<
img alt="" src="images/emo.jpg" />
<
img alt="" src="images/icon068.gif" />
<
img alt="" src="images/icon260.jpg" />
<
input id="btn" type="button" value="Hide Gif's" />
</
div>
</
form>

</
body>
</
html>

Initially all the images will be displayed.

image

On the click of the ‘Hide Gif’s’ button, all the gif’s will get hidden. In our case, the 2nd image is a .gif

image

Add an Image Command Field to a GridView at runtime

If you were looking out to programmatically add an Image Command Field to a GridView, here’s how to do so:

C#

if (!Page.IsPostBack)
{
CommandField field = new CommandField();
field.ButtonType = ButtonType.Image;
field.SelectImageUrl = "~/Images/MyPic.GIF";
field.ShowSelectButton = true;
field.HeaderText = "Select";
GridView1.Columns.Add(field);
GridView1.DataBind();
}

VB.NET

If (Not Page.IsPostBack) Then
Dim
field As New CommandField()
field.ButtonType = ButtonType.Image
field.SelectImageUrl = "~/Images/MyPic.GIF"
field.ShowSelectButton = True
field.HeaderText = "Select"
GridView1.Columns.Add(field)
GridView1.DataBind()
End If
To check out some more GridView tips, look over here ASP.NET GridView Tips and Tricks

Prevent User From Editing Text in a TextBox using jQuery

I was recently solving a requirement where a TextBox having text needed to be made read-only, as soon as focus was set on it. This is a typical scenario where a user reloads a form that is to be presented as read-only. This is how I solved the requirement using jQuery:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title></title>

<
script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<
script type="text/javascript">
$(document).ready(function() {
$("input[type=text]").focus(function() {
if ($(this).val())
$(this).blur().css('background-color', 'gray');
});
});

</script>
</
head>
<
body>
<
form id="form1">
<
div>
<
input id="Text1" type="text" value="Some Text" />
<
input id="Text2" type="text" value="Some Text" />
<
br />
<
input id="Button1" type="button" value="Some Button" />
</
div>
</
form>

</
body>
</
html>

So as soon as you set focus on the textbox, the textbox turns grey indicating that it is read-only and the user is prevented to modify the text.

image