July 10, 2009

Silverlight 3 Released

0 comments

Microsoft Silverlight developers and designers have a reason to rejoice! Silverlight 3 has been released (RTW) and here are some important links:

Silverlight 3 Runtime – Version is Silverlight 3 RTW (3.0.40624.0)

Silverlight 3 SDK - provides libraries and tools for developing Silverlight applications

Silverlight 3 Tools for Visual Studio 2008 SP1- Add-on for Visual Studio 2008 SP1 for developing Silverlight 3 applications

Microsoft Expression Blend 3 + SketchFlow RC - Create Windows Presentation Foundation (WPF) applications for the desktop and Microsoft Silverlight 3 applications for the web

Deep Zoom Composer - Prepare images for use with the Deep Zoom feature in Silverlight 3

Ironically there has been no official announcement about the release yet as of this writing, however the download links are active !

Update: To find out more on the new features of Silverlight 3 and Blend 3, check ScottGu's post over here

July 9, 2009

4 Simple Tools to Find Broken Links in your Site

0 comments

Broken links or a 404 error is a webmaster’s nightmare. The task of detecting linkrots becomes even more challenging when the website is huge. Here are 4 tools that can make this task easier for you, by detecting Broken Links in your Site.

W3C Link Checker – Checks and detects issues in links, anchors and referenced objects in Web pages or full Web sites. Enter the url or webpage address you want to check and click on the ‘Check’ Button. The tool takes sometime to analyze and detect the broken links. There are various other options given in the screenshot below that can be selected while checking links.

imagec

Xenu’s Link Slueth – Is a very popular desktop program that checks your websites for broken hyperlinks, images, frames, plug-ins, backgrounds, local image maps, style sheets, scripts and java applets.

image

Link Checker FireFox AddOn - Check the validity of links on any webpage. Once you have installed this Addon in FireFox, choose ‘Check Page Links’ in the ‘Tools’ menu or right-click on any webpage using FireFox, to invoke this tool.

image

Dead-Link-Checker – A simple web tool that requires JavaScript enabled to detect broken links

image

Other Link Checkers - http://linkchecker.sourceforge.net/other.html

July 8, 2009

Detect Copy, Paste and Cut operations on a TextBox using jQuery

5 comments

To detect Copy, Paste and Cut operations two years ago, I remember using the addEventListener and capturing the keyDown event. Then capture the KeyCode and ctrlKey to detect a copy or paste in JavaScript. Cumbersome!

Here’s how detecting copy, paste and cut operations is a cakewalk in jQuery

Detect Copy, Paste and Cut Operation in a HTML TextBox

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

<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Copying and Pasting in a TextBox</title>

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

<
script type="text/javascript">
$(document).ready(function() {
$("#Text1").bind('copy', function(e) {
alert('copying text!');
});
$("#Text1").bind('paste', function(e) {
alert('pasting text!');
});
$("#Text1").bind('cut', function(e) {
alert('cut text!');
});
});
</script>

</
head>
<
body>
<
input id="Text1" type="text" value="Copy Me" />
</
body>
</
html>



Detect Copy, Paste and Cut Operation in an ASP.NET TextBox

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="jQuery2.aspx.cs" Inherits="jQuery2" %>

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

<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<
title>Handling Copy and Paste functions in TextBox</title>

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

<
script type="text/javascript">
$(document).ready(function() {
$("#TextBox1").bind('copy', function(e) {
alert('copying text!');
});
$("#TextBox1").bind('paste', function(e) {
alert('pasting text!');
});
$("#TextBox1").bind('cut', function(e) {
alert('cut text!');
});
});
</script>
</
head>
<
body>
<
form id="form1" runat="server">
<
div>
<
asp:TextBox ID="TextBox1" runat="server">Copy Me</asp:TextBox>
</
div>
</
form>

</
body>
</
html>


Cool..ain’t it! Just a few lines of code and you can now capture the copy, paste and cut actions on a TextBox, TextArea or any other controls that can respond to these events.

July 7, 2009

Multiple Background Images for an Element in CSS

2 comments

Recently, I observed an interesting issue at one of my client’s webpage. They wanted to add multiple background images to an element. Although as per this document, doing this in CSS is possible

div {
background-image: url(images/emo.jpg) url(images/icon068.gif);
}

however not all browsers support this feature.

To get around this issue, here’s what I proposed which also works cross-browser. The trick is to place a similar element inside the parent element, in our case placing a DIV inside a DIV.

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

<
head>
<
meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<
title>Multiple Background Images</title>
<
style type="text/css">

#outerDiv
{
height:100px;
width:100px;
background-image: url(images/emo.jpg);
background-repeat: repeat-x;
}
#innerDiv
{
height:80px;
width:100px;
background-image: url(images/icon068.gif);
background-repeat: repeat-x;
}

</style>
</
head>

<
body>
<
div id="outerDiv">
<
div id="innerDiv">

</
div>
</
div>
</
body>

</
html>



The output is as shown below with one image placed over the other. To overlap the parent image, change the width from 100px to 80px:

image

July 6, 2009

Import Excel Data Into an ASP.NET GridView using Microsoft.Office.Interop.Excel

0 comments

In my previous article, we saw how to import Excel Data into an ASP.NET GridView using OLEDB. In this next article, we will see how to import Excel Data Into an ASP.NET GridView using Microsoft.Office.Interop.Excel. This untested code was written by Vince Xu -MSFT and I thought of sharing it with you.

C#

using Microsoft.Office.Interop.Excel;
using System.Text;
using System.Reflection;

public partial class ImportDD : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = GetExcel("c:\\aa.xls");
GridView1.DataSource = ds;
GridView1.DataBind();
}

public DataSet GetExcel(string fileName)
{
Application oXL;
Workbook oWB;
Worksheet oSheet;
Range oRng;
try
{
// creat a Application object
oXL = new ApplicationClass();
// get WorkBook object
oWB = oXL.Workbooks.Open(fileName, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);

// get WorkSheet object
oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.Sheets[1];
System.Data.DataTable dt = new System.Data.DataTable("dtExcel");
DataSet ds = new DataSet();
ds.Tables.Add(dt);
DataRow dr;

StringBuilder sb = new StringBuilder();
int jValue = oSheet.UsedRange.Cells.Columns.Count;
int iValue = oSheet.UsedRange.Cells.Rows.Count;
// get data columns
for (int j = 1; j <= jValue; j++)
{
dt.Columns.Add("column" + j, System.Type.GetType("System.String"));
}

// get data in cell
for (int i = 1; i <= iValue; i++)
{
dr = ds.Tables["dtExcel"].NewRow();
for (int j = 1; j <= jValue; j++)
{
oRng = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[i, j];
string strValue = oRng.Text.ToString();
dr["column" + j] = strValue;
}
ds.Tables["dtExcel"].Rows.Add(dr);
}
return ds;
}
catch (Exception ex)
{
return null;
}
finally
{
Dispose();
}
}

}

VB.NET

Imports Microsoft.Office.Interop.Excel
Imports System.Text
Imports System.Reflection

Partial Public Class ImportDD
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As DataSet = GetExcel("c:\aa.xls")
GridView1.DataSource = ds
GridView1.DataBind()
End Sub

Public Function
GetExcel(ByVal fileName As String) As DataSet
Dim oXL As Application
Dim oWB As Workbook
Dim oSheet As Worksheet
Dim oRng As Range
Try
' creat a Application object
oXL = New ApplicationClass()
' get WorkBook object
oWB = oXL.Workbooks.Open(fileName, Missing.Value, Missing.Value,_
Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, _
Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value, _
Missing.Value, Missing.Value)

' get WorkSheet object
oSheet = CType(oWB.Sheets(1), _
Microsoft.Office.Interop.Excel.Worksheet)
Dim dt As New System.Data.DataTable("dtExcel")
Dim ds As New DataSet()
ds.Tables.Add(dt)
Dim dr As DataRow

Dim sb As New StringBuilder()
Dim jValue As Integer = oSheet.UsedRange.Cells.Columns.Count
Dim iValue As Integer = oSheet.UsedRange.Cells.Rows.Count
' get data columns
For j As Integer = 1 To jValue
dt.Columns.Add("column" & j, _
System.Type.GetType("System.String"))
Next j

' get data in cell
For i As Integer = 1 To iValue
dr = ds.Tables("dtExcel").NewRow()
For j As Integer = 1 To jValue
oRng = CType(oSheet.Cells(i, j), _
Microsoft.Office.Interop.Excel.Range)
Dim strValue As String = oRng.Text.ToString()
dr("column" & j) = strValue
Next j
ds.Tables("dtExcel").Rows.Add(dr)
Next i
Return ds
Catch ex As Exception
Return Nothing
Finally
Dispose()
End Try
End Function

End Class

July 5, 2009

Import Excel Data Into An ASP.NET GridView using OLEDB

0 comments

I have seen a lot of users asking how to import data from an excel sheet into an ASP.NET GridView.

I will show two ways to do so - Using OLEDB and Using Microsoft.Office.Interop.Excel

In this post, we will see how to import data using OLEDB

C#

using System.Data.OleDb;
using System.Data;

public partial class UploadD : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string cnstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\a.xls;"
+ "Extended Properties=Excel 8.0";
OleDbConnection oledbConn = new OleDbConnection(cnstr);
string strSQL = "SELECT * FROM [Sheet$]";

OleDbCommand cmd = new OleDbCommand(strSQL, oledbConn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}

VB.NET

Imports System.Data.OleDb
Imports System.Data

Partial Public Class UploadD
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim cnstr As String = "Provider=Microsoft.Jet.Oledb.4.0;" &_
"Data Source=C:\a.xls; Extended Properties=Excel 8.0"
Dim oledbConn As New OleDbConnection(cnstr)
Dim strSQL As String = "SELECT * FROM [Sheet$]"

Dim cmd As New OleDbCommand(strSQL, oledbConn)
Dim ds As New DataSet()
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
End Sub
End Class
In the next article, we will see how to import Excel Data Into an ASP.NET GridView using Microsoft.Office.Interop.Excel

July 4, 2009

How to Open a Page In Full Screen Mode using JavaScript

0 comments

One of my team members had a requirement of opening up a page in Full Screen mode. He wanted that when a link on the page is clicked, the same page should be opened in Full Screen Mode. If you too have a similar requirement, then here’s how to do so:

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

<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Open Page FullScreen</title>
<
script type="text/javascript">
function
FullScreenMode(){
var win = window.open("", "full", "dependent=yes, fullscreen=yes");
win.location = window.location.href;
window.opener = null;
}

</script>

</
head>
<
body>
<
input id="Button1" type="button" value="Full Screen"
onclick="FullScreenMode()"/>
</
body>
</
html>
If you want the parent window to close when the new window opens in full screen mode, just add window.close(); as the last line in the JavaScript code.

 

Copyright 2009 All Rights Reserved DevCurry.com by Suprotim Agarwal