jQuery and ASP.NET

February 28, 2010

Click me Only Once - jQuery

0 comments


I have seen a very frequently asked question by developers – How to execute an event only once. With jQuery, achieving this requirement is very simple using One

Here’s how:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Click me once only</title>
<
script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js">
</
script>
<
script type="text/javascript">
$(function() {
$("#Submit1").one('click', function() {
$(this).val("No more alerts");
alert('');
});
});
</script>
</
head>
<
body>
<
input id="Submit1" type="submit" value="submit" />
</
body>
</
html>


In the code shown above, the click event is fired only once and the alert is displayed. All subsequent clicks will do nothing

Live Demo

February 27, 2010

Visual Studio jQuery Intellisense over CDN

7 comments


Most of us know about the Visual Studio jQuery Intellisense document Visual Studio Intellisense (vsdoc) for jQuery 1.4.1.

However many developers are not aware that you can get vsdoc Intellisense for jQuery over CDN (Content Delivery Network) as well. Just use the Microsoft CDN instead of the Google CDN

Here’s an example of the intellisense showing up with the Microsoft CDN network:

vsdoc intellisense with CDN

vsdoc intellisense with CDN

Microsoft CDN hosts both jQuery and the Visual Studio Intellisense for jQuery.

February 26, 2010

Retrieve the Selected Item of a DropDownList kept inside a UserControl

0 comments


I have often seen developers struggling with accessing properties of controls kept inside a UserControl. This post will show you how to retrieve the selected Item of a DropDownList kept inside a UserControl.

Let us assume that we have a UserControl called UserControlOne.ascx

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="UserControlOne.ascx.cs" Inherits="UserControlOne" %>

<asp:DropDownList ID="DropDownList1" runat="server">
</
asp:DropDownList>

The code to populate the UserControl is as shown below (UserControlOne.ascx.cs):

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string[] names = DateTimeFormatInfo.CurrentInfo.MonthNames;
DropDownList1.DataSource = names;
DropDownList1.DataBind();
}
}

We will now register this UserControl to a page as shown below:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default16.aspx.cs"
Inherits="Default16" %>
<%
@ Register TagPrefix="UC" TagName="DDL" src="UserControlOne.ascx"%>

Now to access the selected item of the dropdownlist kept inside the usercontrol, use the following code on the Button click event:

protected void btnFetch_Click(object sender, EventArgs e)
{
UserControl ucOne = ((UserControl)(FindControl("DDLOne")));
DropDownList ddlOne = ((DropDownList)(ucOne.FindControl("DropDownList1")));
if (ddlOne.SelectedIndex > -1)
Label1.Text = ddlOne.SelectedItem.Value;
}

OUTPUT

DropDownList Inside UserControl

February 25, 2010

Create Nested Directories in C# and VB.NET

1 comments


A lot of developers do not know that Directory.CreateDirectory() can be used to create directories and subdirectories as specified by the path. Here’s an example

C#

static void Main(string[] args)
{
try
{
Directory.CreateDirectory(@"D:\ParentDir\ChildDir\SubChildDir\");
Console.WriteLine("Directories Created");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

VB.NET

Shared Sub Main(ByVal args() As String)
Try
Directory.CreateDirectory("D:\ParentDir\ChildDir\SubChildDir\")
Console.WriteLine("Directories Created")
Console.ReadLine()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub

OUTPUT

CreateNestedDirectories

February 24, 2010

Microsoft Web Application Gallery

0 comments


Here’s a way to get instant access to the most popular free web applications available today. Check out the Windows Web Application Gallery. With just a few clicks you can install some popular web applications and be up and running within minutes.

Microsoft Web Application Gallery

Learn more about the Microsoft Web Application Gallery over here Introducing the Windows Web Application Gallery

February 23, 2010

Display an Image when the GridView has no data

1 comments


I recently answered a question on the forum where a user wanted to display an image when the GridView returns empty data. Now you must be already be familiar with the GridView’s EmptyDataText property which displays a message to the user when there are no results returned from the GridView control’s data source.

Now instead of a text message, if you need to display an image or any HTML/ASP.NET control, you can use the EmptyDataTemplate. In this snippet below, we are using the image control in the <EmptyDataTemplate> to display an image.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
ShowFooter="true" AllowPaging="True" AllowSorting="True"
>

<
EmptyDataTemplate>
<
asp:Image id="imgOne"
ImageUrl="~/images/Emptydata.jpg"
AlternateText="No results"
runat="server"/>
</
EmptyDataTemplate>

February 22, 2010

Professional ASP.NET 4 Book

4 comments


Those who have been doing ASP.NET development and reading ASP.NET books are quite familiar with Wrox author Bill Evjen. He is a leading expert on ASP.NET and has the ability to present complex topics with ease.

Bill along with two other experts (Scott Hanselman, Devin Rader ) has authored a new book on ASP.NET 4.0 called Professional ASP.NET 4 in C# and VB. The book will be released in March and you can pre-order it over here

Professional ASP.NET 4 contains:

  • Demonstrates ASP.NET built-in systems such as the membership and role management systems

  • Covers everything you need to know about working with and manipulating data

  • Discusses the plethora of server controls that are at your disposal

  • Explores new ways to build ASP.NET, such as working with ASP.NET MVC and ASP.NET AJAX

  • Examines the full life cycle of ASP.NET, including debugging and error handling, HTTP modules, the provider model, and more

  • Features both printed and downloadable C# and VB code examples

image

February 21, 2010

Hotmail - The message is too big to be completely displayed. Only the first 768 KB is shown

0 comments


Have you encountered this message while viewing your mail using Hotmail - “The message is too big to be completely displayed. Only the first 768 KB is shown

Well if you are under the impression that there is a solution to it (as I too was hoping before writing this post), then you are in for a surprise! This “feature” is supposedly “by design” and the only solution to it is to configure your mail account in an email client like Windows Live Mail and then read the mail. Read the entire discussion over here

I am sure the Hotmail product team is aware of this “design decision” (and the frustration it causes), as it has been there from quite some time. I can only hope that someone from the team takes a different view to it and starts considering it as an issue that needs to be resolved as soon as possible!

February 20, 2010

.NET 4.0 Beta Exams announced – take them for free

0 comments


The .NET 4.0 Beta Exams were announced recently by Microsoft over here

Here’s a list of exams that will be made available in between March 31, 2010 to April 20, 2010.

70-511 TS: Windows Applications Development with Microsoft® .NET Framework 4
70-513 TS: Windows Communication Foundation Development with Microsoft® .NET Framework 4
70-515 TS: Web Applications Development with Microsoft® .NET Framework 4
70-516 TS: Accessing Data with Microsoft® .NET Framework 4
70-519 Pro: Designing and Developing Web Applications using Microsoft® .NET Framework 4

70-518 Pro: Designing and Developing Windows® Applications using Microsoft .NET Framework 4 will not be available in this time frame but should be available in the April time frame.

Check out this post to register for these exams

Prep time!

February 19, 2010

Creating a CustomFilter on the Silverlight 3 AutoCompleteBox

0 comments


Silverlight 3 has the AutoCompleteBox control which is a textbox that shows suggestions in a drop-down, when the user types text into it. Here’s a very simple example of this control in action.

Just drop in a TextBlock and the Silverlight3 AutoCompleteBox control inside a Canvas as shown below:

 <Canvas x:Name="LayoutRoot" Height="300" Width="300"
HorizontalAlignment="Left">
<
TextBlock Text="Enter Country starting with 'A'"
Canvas.Top="5" Canvas.Left="10"/>
<
input:AutoCompleteBox x:Name="locAuto" Width="200"
Canvas.Top="25" Canvas.Left="10">
</
input:AutoCompleteBox>
</
Canvas>

Type the following code in the code behind file

public MainPage()
{
InitializeComponent();
// Assuming this list comes from a service
List<string> cList = new List<string>();
cList.Add("Afghanistan");
cList.Add("Albania");
cList.Add("Algeria");
cList.Add("American Samoa");
cList.Add("Andorra");
cList.Add("Angola");
cList.Add("Aruba");
locAuto.ItemsSource = cList;
}

Now run the application and on typing ‘A’, a list of suggestions appear in a drop-down fashion. Observe that there are 7 suggestions given to the user.

Silverlight AutoCompleteBox

We will now apply a custom filter to this AutoCompleteBox and filter out those countries whose length is not greater than 5. To do so, create a method that accepts two parameters: the user text and the text that has to be matched

public bool AutoFilter(string text, string item)
{
return (item.Length > 5);
}

The final step is to set the ItemFilter property of the AutoCompleteBox to a delegate that points to our Filter method

locAuto.TextFilter = AutoFilter;

Run the application again and you will find that ‘Aruba’ is not shown as a suggestion since it’s length is not greater than 5

Silverlight AutoCompleteBox

February 18, 2010

Free EBook - Understanding Microsoft Virtualization Solutions

0 comments


This guide will teach you about the benefits of the latest virtualization technologies and how to plan, implement, and manage virtual infrastructure solutions. The technologies covered include: Windows Server 2008 Hyper-V, System Center Virtual Machine Manager 2008, Microsoft Application Virtualization 4.5, Microsoft Enterprise Desktop Virtualization, and Microsoft Virtual Desktop Infrastructure.

image

Download the Free EBook over here

February 17, 2010

jQuery UI DatePicker – Programmatically selecting a Date

0 comments


When the jQuery UI DatePicker shows up, the current date is selected by default as shown below:

jQuery UI DatePicker Default Date

Note: It was the 12th of February, 2010 when I tried this example.

However if you want to programmatically select a date, then here’s how to do so. We will select 15th of February, 2010:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title></title>
<
script src="http://code.jquery.com/jquery-latest.js"
type="text/javascript"></script>
<
script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js">
</
script>
<
link rel="stylesheet" type="text/css" media="screen"
href="http://bit.ly/cNbe6T"/>

<
script type="text/javascript">
$(function() {
$("#datepic").datepicker();
// month is 0 based, hence for Feb we use 1
$('#datepic').datepicker('setDate', new Date(2010, 1, 15));
});
</script>
</
head>
<
body>
<
input id="datepic"/>
</
body>
</
html>

The output is now

jQuery UI DatePicker Select Date

You can also specify number of years, months or days from today. So for example, if I want to specify a date that is 1 month and 2 days from today, then here’s how you can do it

$('#datepic').datepicker('setDate', '+1m 2d');

OUTPUT

jQuery UI DatePicker Select Date

February 16, 2010

Rounded Corners with the Cornerz jQuery plugin

4 comments


I found a useful plugin created by Johan Fox to create rounded corners with ease. The output looked consistent in most of the latest browsers I tested it on. You can download the plugin over here. Here’s how to use this plugin in your applications:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head id="Head1">
<
title>Cornerz Plugin</title>
<
script language="javascript" type="text/javascript"
src="http://code.jquery.com/jquery-latest.js">
</
script>
<
script language="javascript" type="text/javascript"
src="http://github.com/weepy/cornerz/raw/master/cornerz.js">
</
script>
<
style type="text/css">
.cordiv{
height: 200px;
width: 200px;
background-color:Blue;
}
</style>
<
script type="text/javascript">
$(function() {
$('#divOne').cornerz();
$('#divTwo').cornerz({
radius: 45
});
});
</script>
</
head>
<
body>
<
form id="form1">
<
div>
<
div id="divOne" class="cordiv">
</
div>
<
br /><br /><br />
<
div id="divTwo" class="cordiv">
</
div>
</
div>
</
form>
</
body>
</
html>


OUTPUT

Rounded Corners

See a Live Demo

Note: You may experience a lag before the corners are shown. To avoid the lag, download the cornerz plugin on your local machine and then reference it from there.

February 15, 2010

Inheriting Style in Silverlight 3

0 comments


CSS developers are quite familiar with Style Inheritance i.e defining new styles based on existing ones. In Silverlight 3, you can do style inheritance by using BasedOn attribute on Style.

Here’s an example. We will first create two styles (FontSz and FontWt) to style two different buttons as shown below:

<UserControl x:Class="SilverlightSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<
StackPanel x:Name="LayoutRoot" Height="300" Width="300">
<
StackPanel.Resources>
<
ResourceDictionary>
<
Style x:Name="FontSz" TargetType="Button">
<
Setter Property="FontSize" Value="18" />
</
Style>
<
Style x:Name="FontWt" TargetType="Button">
<
Setter Property="FontStyle" Value="Italic"/>
</
Style>
</
ResourceDictionary>
</
StackPanel.Resources>
<
StackPanel>
<
Button Content="Button One" Style="{StaticResource FontSz}"/>
<
Button Content="Button Two" Style="{StaticResource FontWt}"/>
</
StackPanel>
</
StackPanel>
</
UserControl>

The output of this markup will be similar to the following:

Style Inheritance

Now if you want the FontWt style to be based on the FotnSz style, then use the new attribute ‘BasedOn’ as shown below:

<Style x:Name="FontWt" TargetType="Button"
BasedOn="{StaticResource FontSz}">
<
Setter Property="FontStyle" Value="Italic"/>
</
Style>

Now if you run the sample, the output will be as shown below:

Style Inheritance

Observe how Button Two now has two styles – one inherited from FontSz and the other is its own style (FontWt).

February 14, 2010

Visual Studio 2010 and .NET Framework 4 Training Kit – Updated (February Edition)

0 comments


You can download the latest VS 2010 and .NET 4.0 Training Kit over here

This updated kit which works with with Visual Studio 2010 RC and .NET Framework 4 RC, will help you to learn about the latest Visual Studio 2010 features, SharePoint, Application Lifecycle Management and a variety of framework technologies including:

  • C# 4.0
  • Visual Basic 10
  • F#
  • Parallel Extensions
  • Windows Communication Foundation
  • Windows Workflow
  • Windows Presentation Foundation
  • ASP.NET 4
  • Windows 7
  • Entity Framework
  • ADO.NET Data Services
  • Managed Extensibility Framework
  • Visual Studio Team System

Download the Visual Studio 2010 and .NET Framework 4 Training Kit – February Edition and get access to 17 presentations, 22 Demos and 32 Hands-on Labs.

February 13, 2010

Reconfigure TFS 2010 RC to select another Database Edition

0 comments


In this small post, I will show you how to reconfigure Team Foundation Server (TFS) using SQL Server 2008 R2. Here’s some background information:

I had installed TFS 2010 RC with basic settings which means that I had TFS 2010 RC installed on a box which was using SQL Express for storage. Because of this, there were no reporting as well as analysis services facility available. I wanted to change the SQL server Edition without reinstalling TFS. Here’s how I went about it:

- I installed SQL Server 2008 R2 with all the services.

- I started with removing the existing configuration on TFS by executing the tfsconfig tool. I used Program Files\Microsoft Team Foundation Server 2010\Tools path for using the tool

tfsconfig setup /uninstall:all

- Later I ran tfsmgmt configure. I used the advanced option of the wizard so as to select the SQL server instance name and report server.

That’s it. TFS was configured properly using SQL Server 2008 R2!

February 12, 2010

First Look: Microsoft Office 2010 – Free EBook

0 comments


For a limited time, you can download the free eBook First Look: Microsoft Office 2010 by Katherine Murray.

As given on the site, the free eBook (first 14 chapters) contains the following content:

Part I, “Envision the Possibilities,” introduces you to the changes in Office 2010 and shows you how you can make the most of the new features to fit the way you work today.

Part II, “Hit the Ground Running,” focuses on each of the Office 2010 applications in turn, spotlighting the key new features and showing how they relate to the whole.

Part III, “Next Steps with Office 2010,” zooms up to the big picture and provides examples to help you think through interoperability.

image

Download e-book First Look: Microsoft Office 2010 (PDF file, 10.5 MB)

Download e-book First Look: Microsoft Office 2010 (XPS file, 27.9 MB)

February 11, 2010

Visual Studio 2008 jQuery Intellisense - Error updating JScript IntelliSense: Object doesn't support this property

4 comments


I had recently posted about the jQuery 1.4.1 Intellisense support for Visual Studio. A user commented back saying that intellisense did not work for him. He encountered an error in Visual Studio that said “Error updating JScript IntelliSense”

If you are trying out the jQuery intellisense for Visual Studio and encounter the error “Error updating JScript IntelliSense: Object doesn't support this property”, then make sure that you've installed the hotfix that adds JScript Editor support for “-vsdoc.js” IntelliSense documentation files. You can read more about this hotfix here. Once you have applied this hotfix, you should be able to use intellisense for jQuery 1.4.1 as shown below. Just type $( and the check the documentation appear.

image

image

Note: Remember to install Visual Studio 2008 Service Pack 1 before applying the hotfix.

February 10, 2010

Visual Studio Intellisense (vsdoc) for jQuery 1.4.1 now available

2 comments


Visual Studio Intellisense for jQuery 1.4.1 is now available and can be downloaded from the jQuery site

image

I have downloaded both the jQuery 1.4.1 library and the Visual Studio Intellisense documentation for jQuery 1.4.1 and kept it in the Scripts folder.

image

Here’s how I am using the file in a sample application:

image

Observe how the documentation appears in Visual Studio 2008 after I typed $(

Note: You have to only reference the jQuery 1.4.x file in your code and do not have to reference the -vsdoc.js file. Just keep both these files in the same folder. Visual Studio automatically detects a -vsdoc.js file along with your jQuery library and parses the intellisense file instead.

February 9, 2010

Visual Studio 2010 and .NET Framework 4 Release Candidate

0 comments


The Visual Studio 2010 and .NET Framework 4 Release Candidate (RC) is now available to MSDN subscribers from Monday, February 8th. The release will be made available to everyone else on February 10th. You can access the download files over here

You can also go through a series of Visual Studio 2010 Release Candidate Walkthroughs as well as check out the Visual Studio 2010 and .NET Framework 4 Training Kit - January Release

You can take a survey and let the team know about your experiences with this product.

Note: This release does not support Silverlight 4 development. Support for Silverlight 4 with the VS 2010 RC should be made available in the next SL4 code release.

February 8, 2010

C# 4.0 New Features, Videos, Articles and Books

3 comments


I was collecting some learning material on C# 4.0 and stumbled across some useful videos, articles and documents available on C# 4.0. I am just listing a few of them. Check them out!

Samples and Documents

New features of C# 4.0 (Beta 2)

Download C# 4.0 Beta 2 samples and documents

Articles

Use C# 4.0 dynamic to drastically simplify your private reflection code

C# 4.0 Optional Parameters – Exploration

An Overview of C# 4.0

Two New Features of C# 4.0

Looking Ahead to C# 4.0: Optional and Named Parameters

Books

C# 4.0 in a Nutshell: The Definitive Reference

Accelerated C# 2010

Visual C# 2010 Recipes: A Problem-Solution Approach

Introducing .NET 4.0: with Visual Studio 2010

Training Videos

What's New in C# 4.0

C# 4.0 Video Series

C# 4.0 Dynamic with Chris Burrows and Sam Ng

How to Use Named and Optional Arguments in Office Programming (C#)

Dynamic C# and a New World of Possibilities

Update: Also check out Visual Studio 2010 and .NET Framework 4 Training Kit – Updated (February Edition)

Please note that C# 4.0 is in Beta as of this writing.

February 7, 2010

Exploring the unwrap() method in jQuery 1.4

0 comments


As given in the jQuery API documentation, the .unwrap() method removes the element's parent. The matched elements (and their siblings, if any) replace their parents within the DOM structure.

Here’s an example:

<html>
<
head>
<
title>Exploring the unwrap method</title>
<
style type="text/css">
.divOne{
height:40px;
width:100px;
background-color:#808080;
}
.divTwo{
height:20px;
width:50px;
background-color:#f0f0f0;
}
</style>
<
script language="javascript" type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">
</
script>
<
script language="javascript" type="text/javascript">
$(function() {
$("#btn").click(function() {
jQuery('.divTwo').unwrap();
});
});
</script>
</
head>
<
body>
<
form>
<
div class="divOne">
<
div class="divTwo">

</
div>
</
div>
<
input id="btn" type="button" value="Unwrap" />
</
form>
</
body>
</
html>

If you run the code, the display is similar to the following:

image

Clicking on Unwrap, calls the unwrap() method on the jQuery object representing divTwo. The output is as follows:

image

As shown above, unwrap removes the parent of divTwo.

See a Live Demo

February 6, 2010

ASP.NET MVC 2 RC2 Released

0 comments


After the positive feedback from ASP.NET MVC 2 RC1, Microsoft has decided to release RC2 (Release Candidate 2). This release fixes a few bugs in the RC, but adds one big feature, and that's a change to the validation model. The new feature makes the default validation system validate the entire model. In MVC 1.0 and MVC 2 RC, the validation would only happen on the model that was posted to the server. Brad Wilson has done a comprehensive post about this here.

For information on the other changes, you can read the release notes here. ASP.NET MVC 2 RC2 can be downloaded from here.

You can also check some highlights of this release in ScottGu’s blog

February 5, 2010

Simultaneously add Multiple Event Handlers to a Selector using jQuery 1.4

1 comments


With jQuery 1.4, you can add multiple event handlers to a selector by passing a map of event type/handler pairs as shown below:

<html>
<
head>
<
title>Bind Multiple Event Handlers</title>
<
style type="text/css">
.divOne{
height:40px;
width:100px;
background-color:#808080;
}
</style>
<
script language="javascript" type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">
</
script>
<
script language="javascript" type="text/javascript">
$(function() {
$('.divOne').bind({
mouseenter: function() {
$(this).css("background-color", "#f0f0f0");
},
mouseout: function() {
$(this).css("background-color", "#808080");
},
click: function() {
alert("Div was clicked");
}
});
});
</script>
</
head>
<
body>
<
form>
<
div class="divOne">
</
div>
</
form>
</
body>
</
html>

See a Live Demo

Note: In the previous version, you could bind one function to multiple events.

February 4, 2010

How to Reference a JavaScript file from a Content Page

1 comments


When developers reference a JavaScript file in a Master Page and have to use it only in a couple of Content Pages, there is an extra overhead involved, since the file gets referenced for every Content page. To avoid this overhead, you can reference the JavaScript file directly from the Content Pages where the script will be used. Here’s how:

C#

protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptInclude("selective",
ResolveUrl(@"Scripts\TestScript.js"));
if (!Master.Page.ClientScript.IsStartupScriptRegistered("alert"))
{
Master.Page.ClientScript.RegisterStartupScript
(this.GetType(), "alert", "insideJS();", true);
}
}

VB.NET

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Page.ClientScript.RegisterClientScriptInclude("selective", _
ResolveUrl("Scripts\TestScript.js"))
If (Not Master.Page.ClientScript.IsStartupScriptRegistered("alert")) Then
Master.Page.ClientScript.RegisterStartupScript(Me.GetType(), _
"alert", "insideJS();", True)
End If
End Sub

As you can observe, we add a reference to the .js file (TestScript.js) from the Content Page using the ‘RegisterClientScriptInclude’ and then use ClientScript.RegisterStartupScript to register the script with the Page object

I have covered plenty of similar tips and tips tricks of calling JavaScript from Master and Content Pages over here

Calling JavaScript from ASP.NET Master Page and Content Pages - Part I

Calling JavaScript from ASP.NET Master Page and Content Pages - Part II

February 3, 2010

Backward Compatibility Plug-in for jQuery 1.3

0 comments


If you have been using jQuery 1.3 and now plan to upgrade to the latest version jQuery1.4, then take a look at the Backward Compatibility Plug-in for jQuery 1.3. This plug-in is for cases where you're having explicit problems upgrading from jQuery version 1.3 to 1.4

Here is a list of backwards compatibility concerns

To use this plug-in on pages which use jQuery 1.4 and have compatibility issues, use this code

<script src="http://code.jquery.com/jquery.js"></script>
<
script src="http://code.jquery.com/jquery.compat-1.3.js"></script>
New to jQuery 1.4? Read more over here

February 2, 2010

Find all the Silverlight Button Controls On a Page

1 comments


Recently I had to recursively list all the Silverlight Button controls on a Page. I stumbled across a piece of generic code suggested by tucod. Here’s the code for your reference which recursively finds all the Buttons in the VisualTree.

C#

public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
var btns = GetButtonControls(LayoutRoot).OfType<Button>();
foreach (var btn in btns)
{
// btn.Content
}
}

IEnumerable<DependencyObject> GetButtonControls(DependencyObject root)
{
List<DependencyObject> doList = new List<DependencyObject>();
doList.Add(root);
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
doList.AddRange(GetButtonControls(VisualTreeHelper.GetChild(root, i)));

return doList;
}
}

VB.NET

Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
Dim btns = GetButtonControls(LayoutRoot).OfType(Of Button)()
For Each btn In btns
' btn.Content
Next btn
End Sub

Private Function
GetButtonControls(ByVal root As _
DependencyObject) As IEnumerable(Of DependencyObject)
Dim doList As New List(Of DependencyObject)()
doList.Add(root)
For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(root) - 1
doList.AddRange(GetButtonControls(VisualTreeHelper.GetChild(root, i)))
Next i

Return doList
End Function
End Class

The Windows.Media.VisualTreeHelper provides utility methods to traverse object relationships.

OUTPUT

image

February 1, 2010

SlideUp and SlideDown using delay() in jQuery 1.4

0 comments


I am excited with the addition of delay() in jQuery 1.4. The .delay() method allows us to delay the execution of functions that follow it in the queue. I have been using it in a couple of places and here’s a small demo of how useful the delay() method is to chain effects:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<
html>
<
head>
<
title>Delay a Button Click</title>
<
style type="text/css">
.divOne{
height:40px;
width:100px;
background-color:Gray;
}
</style>
<
script language="javascript" type="text/javascript"
src="http://code.jquery.com/jquery-latest.js"></script>
<
script language="javascript" type="text/javascript">
$(function() {
$('.btn').click(function() {
$('.divOne').slideUp(500).delay(1500)
.slideDown(500).delay(1000).slideUp(500);
});
});
</script>
</
head>
<
body>
<
form>
<
div>
<
input id="btnOne" type="button" value="Click Me"
class="btn" />
<
br />
<
div class="divOne">
</
div>
</
div>
</
form>
</
body>
</
html>


Here we first slide up the div for 500 milliseconds, then pause for 1.5 seconds, slide down the div for 500 milliseconds, then pause for 1 second and then slide up the div for 500 milliseconds.

This is just awesome! See a Live Demo

 

Copyright 2010 All Rights Reserved DevCurry.com by Suprotim Agarwal