Reference Highlighting in Visual Studio 2010

There is a nice feature in Visual Studio 2010. It’s called Highlighting Reference.

How this feature works is when you are working on your code in the editor and click on a symbol (class, object, methods, properties, variables), then all instances of the symbol are automatically highlighted. This makes it very easy to locate where a symbol has been used in that document.

You can use CTRL+SHIFT+DOWN ARROW (move down) or CTRL+SHIFT+UP ARROW (move up), to navigate through the highlighted instances of that symbol.

Here’s an example that highlights all instances of View() on the page when i click on any one of the references.

image

If for some reason, you do not see the highlighting, make sure that the feature is turned on by going to Tools > Options > Text Editor > C# > Advanced

image

Change Highlighting Reference Color

If you are not happy with the color used for highlighting, then you have an option to change it. To do so, go to Tools > Options > Environment > Font and Colors > Make sure ‘Text Editor’ is the chosen option in the ‘Show settings for’ section > Choose ‘Highlighted Reference’ in the Display Items List Box and use the Custom button to change the foreground and background color.

image

Replace all Headers Tags using jQuery

Here’s a simple script that replaces all the Header Tags (H1, H2, H3) in a page

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Convert all Header Tags using jQuery</title>
<
script src="jquery-1.4.1.js" type="text/javascript"></script>
<
script type="text/javascript">
$(function () {
$("#btnConvert").click(function () {
$("h1, h2, h3").replaceWith(function () {
return "<b>" + $(this).text() + "</b>";
});
});
});
</script>
</
head>
<
body>
<
div>
<
h1>Paragraph One starts here</h1>
<
p>This is some content of paragraph one</p>
<
h2>Paragraph Two starts here</h2>
<
p>This is some content of paragraph two</p>
<
h3>Paragraph Three starts here</h3>
<
p>This is some content of paragraph three</p>
<
input id="btnConvert" type="button" value="Convert Headers" />
</
div>
</
body>
</
html>



The replaceWith(function) is a new addition in jQuery 1.4 which can return a HTML string.

See a Live Demo

Generate Sequence Diagrams in Visual Studio 2010 Ultimate

I was checking out the new ‘Generate Sequence Diagram’ feature in Visual Studio 2010 and it’s pretty cool!

So if you have a piece of code in a method as shown below and want to generate a sequence diagram for it, just right click the method > ‘Generate Sequence Diagram’

image

You can choose various options like the Call Depth and Call scope as shown below:

image

On hitting the OK button, VIsual Studio 2010 analyzes the code and builds a sequence diagram based on its analysis results as shown below:

image

Impressive, I say!!

Remove All Stylesheets from a Page using jQuery

Here’s a very simple piece of code that removes all stylesheet links from a Page using jQuery

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Remove All Stylesheets From a Page</title>
<
link href="CSS/RoundCorners.css" rel="stylesheet" type="text/css" />
<
link href="CSS/FloatDes.css" rel="stylesheet" type="text/css" />
<
script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js">
</
script>
<
script type="text/javascript">
$(function() {
$("#removeAll").click(function() {
$('link[rel=stylesheet]').remove();
});
});
</script>
</
head>
<
body>
<
div class="sub-level"></div>
<
br />
<
input id="removeAll" type="button" value="Remove All Stylesheets" />
</
body>
</
html>

Originally the page with the stylesheets applied looked similar to the following:

remove stylesheets jquery

and after the Button is clicked and the stylesheets removed, the page looks like this

remove stylesheets jquery

jQuery UI 1.8 with new Plugins and plenty of Bug fixes and improvements

jQuery UI 1.8 was released a couple of days ago (March 23rd 2010) with 5 new Plugins, one new effect and plenty of Bug fixes and improvements. Check the jQuery UI 1.8 Changelog for what has changed from jQuery UI 1.7.2 to 1.8. Here are some highlights of this release:

5 New Plugins

  • Core & Utilities: Position
  • Core & Utilities: Widget Factory
  • Core & Utilities: zIndex
  • Widgets: Autocomplete
  • Widgets: Button

1 New Effect

Added the Fade effect

Bug Fixes

Check the jQuery UI 1.8 Changelog for a list of bug fixes and improvements

Important Links

Here are some important download links:

jQuery UI Download Builder

jQuery UI Getting Started Guide

jQuery UI 1.8 Starter Pack

jQuery UI 1.8 Development Bundle

jQuery UI 1.8 Themes Pack

jQuery UI Upgrade Guide

jQuery UI on Google's CDN

Browser Feature detection using MODERNIZR

I was looking out for a tool that can tell me if a browser has the next-gen features natively implemented or not. I found just the right tool called Modernizr

From the website :

“Modernizr is a small and simple JavaScript library that helps you take advantage of emerging web technologies (CSS3, HTML 5) and uses feature detection to test the current browser against upcoming features like rgba(), border-radius, CSS Transitions and many more”

How do I use this library?

Check out the Documentation.

Simple Count based on a Condition using LINQ

Here’ a simple example demonstrating how to perform a count on a List<> based on a condition

C#

class Program
{
static void Main(string[] args)
{
List<Students> students = new List<Students>();
students.Add(new Students() { StudentId = 1, Marks = 8.0f });
students.Add(new Students() { StudentId = 2, Marks = 5.0f });
students.Add(new Students() { StudentId = 3, Marks = 7.0f });
students.Add(new Students() { StudentId = 4, Marks = 9.5f });
students.Add(new Students() { StudentId = 1, Marks = 9.0f });

var topStudCount = students.Count(r => r.Marks >= 9.0f);
Console.WriteLine("Students with Marks >=9 are {0}", topStudCount);
Console.ReadLine();
}
}

class Students
{
public int StudentId { get; set; }
public float Marks { get; set; }
}

VB.NET

Use this Converter Tool

OUTPUT

LINQ Count

Create a Trial Version/Shareware .NET application

I see plenty of questions around creating shareware applications. Although there are some tools and code available on the web that let you do that, I thought of writing this post to let you know about the FREE Shareware Starter Kit

The Shareware Starter Kit was released a couple of years ago by Microsoft and is a sample application that implements the common features in shareware applications. Although this was released a couple of years ago, you can easily follow the code to create one of your own or enhance it further. Here are some features of this starter kit

- integrated e-commerce using PayPal for users to purchase a licensed copy of your software via webservices

- Try and Buy feature which lets you configure your application for a trial period before prompting the user for a secure product activation

- A simple form to let you register the product as well as accept customer feedback directly from the product using webservices

- Capturing errors and exceptions and reporting using Web services.

I hope you find the Shareware Starter Kit useful to create your own Shareware applications

You can see a Demo of this kit over here

Simple Image SlideShow using jQuery

I have seen a lot of users requesting for simple jQuery scripts for SlideShows. I saw a couple of them, but the scripts assumed that the number of image tags has to be fixed beforehand.

The code given below is taken from my eBook “51 Recipes with jQuery and ASP.NET Controls”.

Note: This code was written when jQuery 1.3.2 was the latest version available. Currently we have jQuery 1.4.2 available.

<html xmlns="http://www.w3.org/1999/xhtml">
<
head id="Head1" runat="server">
<
title>Simple Image SlideShow</title>
<
link href="../CSS/Demos.css" rel="stylesheet" type="text/css" />
<
script type='text/javascript'
src='../Scripts/jquery-1.3.2.min.js'>
</
script>

<
script type="text/javascript">
$(function() {

var imgs = [
'../images/1.jpg',
'../images/2.jpg',
'../images/3.jpg',
'../images/4.jpg'];
var cnt = imgs.length;

var $imageSlide = $('img[id$=imageSlide]');
// set the image control to the last image
$imageSlide.attr('src', imgs[cnt-1]);

setInterval(Slider, 3000);

function Slider() {
$imageSlide.fadeOut("slow", function() {
$(this).attr('src', imgs[(imgs.length++) % cnt])
.fadeIn("slow");
});
}
});

</script>

</
head>
<
body>
<
form id="form1" runat="server">
<
div class="smallDiv">
<
h2>Image Slide Show - Image Changes Every 3 Seconds</h2><br />
<
asp:Image ID="imageSlide" runat="server" class="imgdiv" />
</
div>
</
form>
</
body>
</
html>


This recipe shows you how to create a simple image slideshow that works in modern browsers. This example starts by declaring an array containing image paths. We have declared an image control on the page. When the page loads, the image path of this control is set to the last element of the array. I will explain shortly why this is needed.

var $imageSlide = $('img[id$=imageSlide]');
// set the image control to the last image
$imageSlide.attr('src', imgs[cnt-1]);

We then use the JavaScript setInterval() function which delays execution of the Slider function for a specific time, in our case 3000 millisecond(3 seconds). The advantage of a setInterval() function is that it continues to repeat the process of triggering the function at a specified interval, thereby sliding the images in a cycle. If you want to pause the slideshow, use the clearInterval() function.

Note: Since the Slider function is first called after a 3 seconds delay, hence we explicitly set the image control source to the last image path in the array. If we do not do so, the user does not see an image for the first 3 seconds.

With every loop, we set the image control source to the next element in the array using the expression imgs[(imgs.length++) % cnt] and apply the fadeIn() and fadeOut() effect.

function Slider() {
$imageSlide.fadeOut("slow", function() {
$(this).attr('src', imgs[(imgs.length++) % cnt])
.fadeIn("slow");
});
}

See a Live Demo

Generate Stronger Random Numbers using C# and VB.NET

The RNGCryptoServiceProvider Class implements a cryptographic Random Number Generator (RNG) using the implementation provided by the cryptographic service provider (CSP). Here’s how to generate random numbers using this class. Make sure you import the System.Security.Cryptography namespace before using this sample code

C#

static void GenerateRandomNumber()
{
byte[] byt = new byte[4];
RNGCryptoServiceProvider rngCrypto =
new RNGCryptoServiceProvider();
rngCrypto.GetBytes(byt);
int randomNumber = BitConverter.ToInt32(byt, 0);
Console.WriteLine(randomNumber);
}

VB.NET

Shared Sub GenerateRandomNumber()
Dim byt As Byte() = New Byte(4) {}
Dim rngCrypto As New RNGCryptoServiceProvider()
rngCrypto.GetBytes(byt)
Dim randomNumber As Integer = BitConverter.ToInt32(byt, 0)
Console.WriteLine(randomNumber)
End Sub

image

Using jQuery to find out Elements on the Page that do not have an ID attribute

In this post, I will demo a simple selector to find out elements on the page that do not have an ID attribute declared on them

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Input Elements that do not have an ID attribute</title>
<
script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js">
</
script>

<
script type="text/javascript">
$(function () {
$('div :not([id])').css("border", "2px Black solid");
// for only input elements
//$('div input:not([id])').css("border", "2px Black solid");
});
</script>
</
head>
<
body>
<
div>
<
input id="Button1" type="button" value="button" />
<
input id="Text1" type="text" />
<
input type="password" />
<
input type="radio" />
<
input id="Checkbox1" type="checkbox" />
<
img src="images/Desert.jpg" height="200" width="200" />
</
div>
</
body>
</
html>


The code shown above uses the :not() selector to find elements without the id attribute and adds a black border around the elements.

image

Generate Odd Numbers within a Range using LINQ

The Enumerable.Range method generates a sequence of integral numbers within a specified range. Here’s how to use it to generate a sequence of odd numbers within a given range say 20 to 40:

C#

static void Main(string[] args)
{
IEnumerable<int> oddNums =
Enumerable.Range(20, 20).Where(x => x % 2 != 0);

foreach (int n in oddNums)
{
Console.WriteLine(n);
}
Console.ReadLine();

}

VB.NET

Sub Main(ByVal args() As String)
Dim oddNums As IEnumerable(Of Integer) = _
Enumerable.Range(20, 20).Where(Function(x) x Mod 2 <> 0)

For Each n As Integer In oddNums
Console.WriteLine(n)
Next n
Console.ReadLine()

End Sub

Note: Just remember that the Enumerable.Range accepts two parameters: Start and Count. So if you want to generate numbers from 25 to 50 (inclusive of both), you would say Enumerable.Range(25,26) since the second parameter is the number of sequential integers to generate.

OUTPUT

Generate Odd Numbers LINQ

Learn Silverlight using this Free Online Training Program

Microsoft recently announced the launch of .toolbox! .toolbox is a free online training program where designers and developers can learn to create Silverlight applications using Expression Studio and to apply basic UX concepts to their solutions.

.toolbox

Once you visit .toolbox, Sign-In using your LiveID and create a profile

.toolbox

and then your avatar.

.toolbox

You are all set to now attend the Silverlight School! Select a module, watch the videos, and follow along using the provided guide and assets. Take the evaluation for a completed level to achieve a badge. Broadcast your achievements by posting to Twitter and Facebook! Watch a .toolbox YouTube video to learn more.

Happy Learning!

Join Two String Arrays with Distinct values using LINQ

One of my colleagues was looking out for a simple way to join two string arrays and avoid duplicates (if any) in those arrays. I asked him to use the Union method which excludes duplicates from the return set.

C#

static void Main(string[] args)
{
string[] arr1 = { "One", "Two", "Four", "Six" };
string[] arr2 = { "Three", "Two", "Six", "Five" };

var arr3 = arr1.Union(arr2);

foreach (string n in arr3)
{
Console.WriteLine(n);
}
Console.ReadLine();

}

VB.NET (option infer on)

Sub Main(ByVal args() As String)
Dim arr1() As String = { "One", "Two", "Four", "Six" }
Dim arr2() As String = { "Three", "Two", "Six", "Five" }

Dim arr3 = arr1.Union(arr2)

For Each n As String In arr3
Console.WriteLine(n)
Next n
Console.ReadLine()

End Sub

OUTPUT

Merge String Arrays LINQ

Silverlight 4 Release Candidate

During the MIX10 Keynote on March 15, 2010, Scott Guthrie announced the release of Silverlight 4 Release Candidate (RC). The final release is expected to be sometime in April this year. One of the other related announcements that got me all excited was that we can now create apps for Windows Phone 7 using Silverlight 4.

Here are some important links related to this release:

Getting Started with Silverlight 4

What’s New in Silverlight 4?

Download Silverlight 4 Tools

Add a Twitter Button into Blogger next to the Post Title

You must have observed the new Twitter Button on each post. Within minutes of adding it, a devcurry reader mailed me asking how I implemented the code. It’s quite easy. I am using the tweetmeme service to add a Twitter Button into Blogger with the help of this post Integrating the button into Blogger

Step 1: Sign Into your Blogger account > Layout > Edit HTML. Make sure you save a copy by clicking the link ‘Download Full Template’. Check the box ‘Expand Widget Templates’

Step 2: Copy the code shared in the link I shared earlier. Now this code adds the twitter button at the end of each post. However what we want is to add a Twitter Button next to the Post Title.

Making sure you have checked the box ‘Expand Widget Templates’, search for the text ‘post-header-line-1’

Blogger Twitter Button

Step 3: Just before the closing div tag, add the following code as shown below:

<b:if cond='data:blog.homepageUrl != data:blog.url'>
<script type='text/javascript'>
tweetmeme_url = &#39;<data:post.url/>&#39;;
</script>
<script src='http://tweetmeme.com/i/scripts/button.js type='text/javascript'> </script>
</b:if>

Blogger Twitter Button

The piece of code 'data:blog.homepageUrl != data:blog.url' checks if the page is not the homepage url and displays the button only on individual posts.

Step 4: Preview the template and then save it.

Now every post of your should have the Tweet Button displayed next to the Post Title

Blogger Twitter Button

Replace Extensions of Images from .jpg to .png using jQuery

A recent requirement demanded that all the .jpg images on a page be replaced with .png’s. Here’s how to solve this requirement using jQuery

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Change Image Extensions</title>
<
script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js">
</
script>
<script type="text/javascript">
$(function() {
$("#replAll").click(function() {
$('img').each(function() {
var src = $(this).attr("src");
$(this).attr("src", src.replace(/\.jpg$/i, ".png"));
});
});
});
</script>
</
head>
<
body>
<
input id="replAll" type="button" value="Replace" /><br />
<
img src="images/abc.jpg" />
<
img src="images/emo.jpg" />
</
body>
</
html>

OUTPUT

jQuery change extensions

Clicking on the ‘Replace’ button changes all .jpg’s to their .png’s counterpart. I have used different images to be able to demonstrate that the images did get changed.

jQuery change extensions

Smarter Intellisense in Visual Studio 2010

Intellisense in Visual Studio 2010 just got smarter! VS 2010 now not only does a search for the text based on the starting letters, it also does a search for “sub-string” occurrences for the text and prompts a list of possible occurrences. Here’s an example. I have declared a textbox control called ‘txtIAmATextboxWithALongName’

Now observe as I type a substring ‘lon’, the intellisense brings up the control name

Intellisense VS 2010

Cool!

Test out Windows Azure AppFabric Technologies using AppFabric Labs

The AppFabric team has released the AppFabric LABS environment. This environment can be used by customers to test out and play with experimental AppFabric technologies, free of cost.

The AppFabric also plans to use this environment to showcase some early bits and get feedback from the community. Read More over here Now Available: The Windows Azure platform AppFabric LABS Environment

What is the Windows Azure AppFabric?

Windows Azure platform AppFabric helps developers connect applications and services in the cloud or on-premises. This includes applications running on Windows Azure, Windows Server and a number of other platforms including Java, Ruby, PHP and others. It provides a Service Bus for connectivity across network and organizational boundaries, and Access Control for federated authorization as a service. Read more

ASP.NET MVC 2 Released

Today Scott Guthrie announced on his blog the release of ASP.NET MVC 2. The release is now available for VS 2008/Visual Web Developer 2008 Express with ASP.NET 3.5. You can download and install it from the following locations:

As with the first release, Microsoft is releasing the source code if you want to take a look at what makes MVC tick. That can be downloaded from here.

ASP.NET MVC 2 can be installed side by side with ASP.NET MVC 1. If you want to upgrade your existing ASP.NET MVC 1 website to ASP.NET MVC 2, Microsoft have created a white paper with instructions on how to do this. That can be downloaded from here.

Some of the new features added to ASP.NET MVC 2 are:

· Strongly typed HTML helpers

· Areas

· Asynchronous controllers

· Auto-Scaffold UI Helpers with template customization

· Enhanced client and server model validation

A comprehensive list of all the new features can be found here.

View Call Hierarchy in Visual Studio 2010

Visual Studio 2010 contains a very useful feature called ‘View Call Hierarchy’. This feature lets you dive into all the calls that are made ‘to’ a method, property or constructor as well as all the calls that are made ‘from’ that method, property or constructor. As given in the documentation “You can examine several levels of code to view complex chains of method calls and additional entry points to the code, which enables you to explore all possible execution paths

For example, right clicking on the LogOff() method brings up the ‘View Call Hierarchy’ option in the context menu

View Call Hierarchy

Clicking on the ‘View Call Hierarchy’ option brings up the following window which displays the calls that are made to LogOff() as well as the calls that are made from LogOff().

View Call Hierarchy

Double clicking these calls takes you to the specific line of code where the call is made from or where the call is made to. Extremely handy!

Convert a JavaScript object to JSON

A colleague of mine was recently searching for a plug-in or script that can convert a JavaScript array to JSON. I asked him to check out JSON.stringify() in the json2.js library, which serializes the JavaScript object into JSON text. Here’s a sample if you do not know about this library:

Note: Make sure that you minify this library and then use the .js directly from your application. For demo purposes I am referring to this .js file directly. In production applications, it is not advisable to do so.

<script type="text/javascript" src="http://www.json.org/json2.js">
</
script>
<
script type="text/javascript">
var
arrCars = new Array("Toyota", "Mercedes", "BMW");
var jsonStr = JSON.stringify(arrCars);
alert(jsonStr);
</script>
JavaScript to JSON

Regular Expression for Phone Numbers

I was looking out for Regular Expressions for validating Phone Numbers of different countries. Here are some of them:

French Phone Number - (0( \d\d ))?\d\d \d\d(\d \d \d\d )\d\d

German Phone Number - ((\(0\d\d\) (\(0\d{3}\) )?\d )?\d\d \d\d \d\d\(0\d{4}\) \d \d\d-\d\d?)

Japanese Phone Number - (0\d{1,4}-\(0\d{1,4}\) ?)?\d{1,4}-\d{4}

P.R.C Phone Number - (\(\d{3}\)\d{3}-)?\d{8}

U.S Phone Number - ((\(\d{3}\) ?)(\d{3}-))?\d{3}-\d{4}

P.S: I did not create these regular expressions. If you are using ASP.NET and Visual Studio 2008/2010, you can easily get these expressions by dropping a RegularExpression Validator and browsing through the Regular Expression Editor ( Select the Validator > Properties > ValidationExpression)

Regex phone number

If you are looking out for some more Regular Expressions, check out these two sites with plenty of resources on it Regular-Expression.info and RegularExpressionLibrary

Measuring ViewState of your Page with a Simple tool

Whenever I come across performance related issues due to the ViewState, I use the ASP.NET ViewState Helper tool from Binary Fortress. Although there are many other tools that help you measure viewstate, I like this tool as its very simple to use.

Assuming you have downloaded it from here, just run it.

Now open an ASP.NET Page in either IE or Firefox and start monitoring the page ViewState right away! Here’s a sample screenshot of some ASP.NET Pages I browsed for demo purpose

ViewState Measure

According to the product description:

ASP.NET ViewState Helper gives you very detailed information to help you optimize your web application’s performance. It allows you to see the following details about each page:

  • Page’s total size: This is the total size of the web page shown in the URL column
  • ViewState size: This is the size of the ViewState field
  • ViewState %: What percent of the total page size is being taken up by the ViewState?
  • Markup size: The size of HTML markup (non-visible text) on the page
  • Markup %: What percent of the page consists of non-visible HTML markup?

Double-click any URL in the list to bring up the ViewState Decoder window. If the selected page contains a ViewState, it will be decoded into plain text, and also broken down into a tree-view for easy analysis.

Check it out. It’s free and helpful!

Free Live Web Sessions at Zeollar

Zeollar is A Microsoft India Developer and Platform Evangelism (DPE) initiative that gets you the latest technical content on a daily basis in different channels. Currently the site has sessions for Developers (ASP.NET, Silverlight, Azure, Visual Studio, SQL Server) and IT Pros and very soon, they plan to introduce sessions for Architects and Designers too.

Zeollar

The site has handy widgets (shown below) to let you browse through related sessions or view the latest ones.

Zeollar

You can also check out the latest schedule and plan your daily dose of technology!

Zeollar

So visit Zeollar to attend free sessions and make sure you provide them feedback.

Using Regular Expression to Validate a Decimal Number

One of my clients had a requirement where a decimal input could not exceed 5,2 characters. In other words, the integral part of the decimal could not exceed more than 5 digits and the fractional part could not exceed more than 2 digits.

Eg: 99999.22 where 99999 is integral part and 22 is fractional

Here’s how to solve this requirement using a Regular expression:

<asp:TextBox ID="txtN" runat="server"></asp:TextBox>
<
asp:RegularExpressionValidator id="myRegex" runat="server"
ControlToValidate="txtN" ValidationExpression="^[0-9]{1,5}(\.[0-9]{0,2})?$"
ErrorMessage="Decimal out of range" />

The expression ^[0-9]{1,5}(\.[0-9]{0,2})?$ checks if the integral part is between 1 to 5 digits and the fractional part is between 0 to 2 digits. Here are some tests.

Decimal Regex

Windows AppFabric Beta 2 Released

On Monday, March 1st, Windows Server AppFabric Beta 2 was released and now is publicly available for download. First announced at PDC 2009, Windows Server AppFabric is a set of application services focused on improving the speed, scale, and management of Web, Composite, and Enterprise applications. Download AppFabric Beta 2

What is AppFabric?

As given on the site, Windows Server AppFabric “is a set of integrated technologies that make it easier to build, scale and manage web and composite applications that run on IIS. AppFabric enhances Windows Server to better scale and manage .NET applications built using Windows Communication Foundation, Windows Workflow Foundation and ASP.NET

Windows Server AppFabric brings together technologies previously codenamed “Dublin” and “Velocity”.

Read more about AppFabric here. You can also learn more about App Fabric.

WHOIS Information using Windows Command Line

Here’s a simple way to view WHOIS information using Windows Command Line. Just download the WHOIS command-line client called Whois v1.01 from Microsoft as part of its Sysinternals Suite. I have copied it in D:\Utils

Now open the Command Line and type the following command:

whois somesite.com or

whois ipaddress

The results are as shown below:

WHOIS CommandLine

Programmatically determine if a Windows Service is running and stop it

The ServiceController class makes it easy to retrieve information about a windows service and manipulate it. Here’s some code. Before running this example, make sure you have added a reference to System.ServiceProcess

C#

static void Main(string[] args)
{
try
{
ServiceController controller = new ServiceController("SERVICENAME");

if (controller.Status.Equals(ServiceControllerStatus.Running)
&& controller.CanStop)
{
controller.Stop();
Console.WriteLine("Service Stopped");
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

VB.NET

Shared Sub Main(ByVal args() As String)
Try
Dim
controller As New ServiceController("SERVICENAME")

If controller.Status.Equals(ServiceControllerStatus.Running)_
          AndAlso controller.CanStop Then
controller.Stop()
Console.WriteLine("Service Stopped")
End If
Console.ReadLine()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub

Make sure you have permission to stop the service or else you will get an exception.

Disable All or Selective Controls on a Page using jQuery

Disabling controls on a Page using jQuery is a cakewalk, thanks to the wonderful Selector API. Here’s an example. I have kept a couple of controls on the page and will show you some ways to disable all or selective controls on a Page using jQuery.

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Disable All Controls on a Page</title>
<
script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1.min.js">
</
script>
<script type="text/javascript">
$(function() {
$("#disableAll").click(function() {
$("*").attr('disabled', 'disabled');
});
});
</script>
</
head>
<
body>
<
input id="Button1" type="button" value="button" /><br />
<
input id="Text1" type="text" /><br />
<
input id="Checkbox1" type="checkbox" /><br />
<
input id="Radio1" type="radio" /><br />
<
textarea id="TextArea1"
cols="20" rows="2"></textarea><br />
<
select id="Select1">
<
option>One</option>
<
option>Two</option>
</
select><br />
<
input id="disableAll" type="submit"
class="disb" value="Disable All" />
</
body>
</
html>

The code shown above disables all the controls on the page. Now if you want to disable only certain type of controls, use this piece of code instead

$(function() {
$("#disableAll").click(function() {
$('input, textarea, select')
.attr('disabled', 'disabled');
});
});

and to be able to filter out one particular control, like to prevent the ‘Disable All’ button from getting disabled, use this piece of code

$(function() {
$("#disableAll").click(function() {
$('input:not(.disb), textarea, table, select')
.attr('disabled', 'disabled');
});
})

Observe that the button ‘Disable All’ has the class '.disb' and we are using the input:not(.disb) selector to select all input elements without the .disb class.

Disable ALL jQuery

Note: To be able to use it on an ASP.NET Page, just replace the HTML controls with Server controls. There’s no change needed in the jQuery code unless you are doing anything specific to your requirement.

Here’s a Live Demo

jQuery events stop working in ASP.NET AJAX UpdatePanel

In a recent forum discussion, a user was facing an issue where his jQuery events would stop working after a partial page postback. Here’s the code that worked before a partial page update occurred

<html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<
title></title>
<
script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<
script type="text/javascript">
$(function() {
$('#link').click(function() {
$('#a').toggle(550);
});
});
</script>
</
head>
<
body>
<
form id="form1" runat="server">
<
div>
<
asp:ScriptManager ID="ScriptManager1" runat="server">
</
asp:ScriptManager>
<
asp:UpdatePanel ID="UpdatePanel1" runat="server">
<
ContentTemplate>
<
a href="#" id="link">Toggle</a>
<
div id="a">my content</div>
<
asp:Button ID="Button1" runat="server" Text="Button" />
</
ContentTemplate>
</
asp:UpdatePanel>

</
div>
</
form>
</
body>
</
html>

The code shown above toggled the Div contents whenever the link was clicked. Now as soon as the Button was clicked and a postback occured, the link would stop toggling the Div contents.

This behavior occurred as during a postback, the UpdatePanel replaces all its contents. So this means that you have to rebind the events to the control after the postback.

A simple solution to this issue is to use the live() event which attaches a handler to the event for all elements which match the current selector, now or in the future. Just replace the code to use the live event and the code should work well even after a postback

<script type="text/javascript">
$(function() {
$('#link').live("click", function() {
$('#a').toggle(550);
});
});
</script>