Saturday, January 22, 2011

JQuery UI 1.8.9 new version launch today

JQuery UI contains great controls and it’s very useful when developing sites. Today a new version of Jquery UI is launched.

You can find more details about that from following link.

http://blog.jqueryui.com/2011/01/jquery-ui-1-8-9/

It’s contains Bug fixes for Datepicker, Tabs and other things and also contains some localization improvements on the date picker.

Technorati Tags: ,
Shout it
Share:

Multi Monitor Support in Visual Studio 2010

In this blog post we are going to see an new feature for multi monitor support in Visual Studio 2010. In Visual Studio 2010 you can drag windows outside IDE and thus you can use in different monitor. That’s feature is very useful if developer is having multiple monitor and he can work different windows at same time.

You just need to drag window outside the IDE and new windows will open just like following.

Multi monitor support in Visual Studio 2010

That’s it you can drag this windows any where. Visual studio 2010 also provide facility to open different IDE in different windows and developer work on multiple solutions at time.

Hope you liked it. Stay tuned for more!!. Happy Programming..

Shout it
Share:
Friday, January 21, 2011

HTML and Java Script code snippets in Visual Studio 2010

We all love Visual Studio as great IDE and Microsoft is providing more and more features for that IDE. Let’s investigate one of great features that Microsoft has given with Visual Studio 2010.

What is code snippets?

Code snippets is a one of the cool feature that given in Visual Studio IDE. If you know the chunks of the code that you need to type over and over again throughout the code then this code snippets feature will help you on this. For example your exception handling code. Your redirection code everything you need more can be putted in the code snippets.

You can insert code snippets via right click –> Insert code snippets and there is also a short code is also available to bring up directly code snippets via pressing ctrl-K+ ctrl-X. Following is look of basic code snippets window.

CodeSnippets with visual studio 2010

You can put your code snippets. Below is link for creating code snippets in Visual Studio 2010.

http://msdn.microsoft.com/en-us/library/ms165394.aspx

HTML and Java Script Code snippets in Visual Studio 2010

Till visual studio 2008 the code snippets are provide only on the code behind file. But with Visual Studio 2010 now you can have that in HTML and as well Java Script code snippets also and even If you have asp.net MVC installed with Visual Studio 2010. You can have code snippets for that also.

Here you can see HTML code snippets in asp.net web form file below.

HTMLCodeSnippet in visual Studio 2010

Same way you can have it Javascript code snippets also like following.

JavascriptSnippets

Isn’t that cool? Stay tuned for more!! Happy programming.

Shout it
Share:
Thursday, January 13, 2011

HTTP Module in details

I know this post may sound like very beginner level. But I have already posted two topics regarding HTTP Handler and HTTP module and this will explain how http module works in the system. I have already posted What is the difference between HttpModule and HTTPHandler here. Same way I have posted about an HTTP Handler example here as people are still confused with it. In this post I am going to explain about HTTP Module in detail.

What is HTTP Module?

As we all know that when ASP.NET Runtimes receives any request it will execute a series of HTTP Pipeline extensible objects. HTTP Module and HTTP handler play important role in extending this HTTP Pipelines. HTTP Module are classes that will pre and post process request as they pass into HTTP Pipelines. So It’s one kind of filter we can say which will do some procession on begin request and end request.

If we have to create HTTP Module we have to implement System.Web.IHttpModule interface in our custom class. An IHTTP Module contains two method dispose where you can write your clean up code and another is Init where your can write your custom code to handle request. Here you can your event handler that will execute at the time of begin request and end request.

Let’s create an HTTP Module which will just print text in browser with every request. Here is the code for that.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Experiment
{
public class MyHttpModule:IHttpModule
{
public void Dispose()
{
//add clean up code here if required
}

public void Init(HttpApplication context)
{
context.BeginRequest+=new EventHandler(context_BeginRequest);
context.EndRequest+=new EventHandler(context_EndRequest);

}
public void context_BeginRequest(object o, EventArgs args)
{
HttpApplication app = (HttpApplication)o;
if (app != null)
{
app.Response.Write("<h1>Begin Request Executed</h1>");
}
}
public void context_EndRequest(object o, EventArgs args)
{
HttpApplication app = (HttpApplication)o;
if (app != null)
{
app.Response.Write("<h1>End Request Executed</h1>");
}
}
}
}
Here in above code you can see that I have created two event handler context_Beginrequest and context_EndRequest which will execute at begin request and end request when request are processed. In this event handler I have just written a code to print text on browser.

Now In order enable this HTTP Module in HTTP pipeline we have to put a settings in web.config HTTPModules section to tell which HTTPModule is enabled. Below is code for HTTPModule.

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpModules>
<add name="MyHttpModule" type="Experiment.MyHttpModule,Experiment"/>
</httpModules>
</system.web>

</configuration>

Now I just have created a sample webform with following code in HTML like following.
<form id="form1" runat="server">
<B>test of HTTP Module</B>
</form>
Now let’s run this web form in browser and you can see here it the output as expected.

HTTPModule

Technorati Tags: ,,
Shout it
Share:

DotNetJalps Nnews- New feed address.

Hello All,

I am moving my feeds to new address so please update your feeds with my new address. Earlier there was two or three feed address and that’s why there were some confusion between the feed address among readers. So I decided to just keep one feed address for all and so I am migrating my all the feeds to following address with feed burner. There will one feed address all the things in blog. So please please update your feed address.

Following is my feed address with feed burner.

http://feeds.feedburner.com/blogspot/DotNetJalps

Still my old feed address will be available for next 30 days and then it will be deleted so please please migrate to this new feed address. 

All reader of the this blog very important because without their support It would not be possible to write blogs. So any suggestion or anything that could make my blog better is always welcome. Please read my blogs regularly and I will also try my best write my blog continuously.

I am still saying that blogging is important now days. It will increase your confidence as well in future it will be integral part of your resume. So if you are still not started blogging then start it immediately. Please read my blog post why a developer should write blog and start working on blog. Because it a shadow of your knowledge to out side world and with blogging your writing and communication skills will also improve that help you in your professional life.

Till that.. Happy programming..Stay tuned for more.

Technorati Tags: ,
Shout it
Share:
Sunday, January 9, 2011

Converting a generic list into JSON string and then handling it in java script

We all know that JSON (JavaScript Object Notation) is very useful in case of manipulating string on client side with java script and its performance is very good over browsers so let’s create a simple example where convert a Generic List then we will convert this list into JSON string and then we will call this web service from java script and will handle in java script.

To do this we need a info class(Type) and for that class we are going to create generic list. Here is code for that I have created simple class with two properties UserId and UserName

public class UserInfo
{
public int UserId { get; set; }
public string UserName { get; set; }
}
Now Let’s create a web service and web method will create a class and then we will convert this with in JSON string with JavaScriptSerializer class. Here is web service class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Experiment.WebService
{
/// <summary>
/// Summary description for WsApplicationUser
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WsApplicationUser : System.Web.Services.WebService
{

[WebMethod]
public string GetUserList()
{
List<UserInfo> userList = new List<UserInfo>();
for (int i = 1; i <= 5; i++)
{
UserInfo userInfo = new UserInfo();
userInfo.UserId = i;
userInfo.UserName = string.Format("{0}{1}", "J", i.ToString());
userList.Add(userInfo);

}
System.Web.Script.Serialization.JavaScriptSerializer jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer();
return jSearializer.Serialize(userList);
}
}
}

Note: Here you must have this attribute here in web service class ‘[System.Web.Script.Services.ScriptService]’ as this attribute will enable web service to call from client side.Now we have created a web service class let’s create a java script function ‘GetUserList’ which will call web service from JavaScript like following
function GetUserList() {
Experiment.WebService.WsApplicationUser.GetUserList(ReuqestCompleteCallback, RequestFailedCallback);

}
After as you can see we have inserted two call back function ReuqestCompleteCallback and RequestFailedCallback which handle errors and result from web service. ReuqestCompleteCallback will handle result of web service and if and error comes then RequestFailedCallback will print the error. Following is code for both function.
function ReuqestCompleteCallback(result) {

result = eval(result);
var divResult = document.getElementById("divUserList");
CreateUserListTable(result);

}
function RequestFailedCallback(error) {

var stackTrace = error.get_stackTrace();
var message = error.get_message();
var statusCode = error.get_statusCode();
var exceptionType = error.get_exceptionType();
var timedout = error.get_timedOut();

// Display the error.
var divResult = document.getElementById("divUserList");
divResult.innerHTML = "Stack Trace: " + stackTrace + "<br/>" +
"Service Error: " + message + "<br/>" +
"Status Code: " + statusCode + "<br/>" +
"Exception Type: " + exceptionType + "<br/>" +
"Timedout: " + timedout;
}

Here in above there is a function called you can see that we have use ‘eval’ function which parse string in enumerable form. Then we are calling a function call ‘CreateUserListTable’ which will create a table string and paste string in the a div. Here is code for that function.
function CreateUserListTable(userList) {

var tablestring = '<table ><tr><td>UsreID</td><td>UserName</td></tr>';

for (var i = 0, len = userList.length; i < len; ++i)
{
tablestring=tablestring + "<tr>";
tablestring=tablestring + "<td>" + userList[i].UserId + "</td>";
tablestring=tablestring + "<td>" + userList[i].UserName + "</td>";
tablestring=tablestring + "</tr>";
}
tablestring = tablestring + "</table>";
var divResult = document.getElementById("divUserList");
divResult.innerHTML = tablestring;
}
Now let’s create div which will have all html that is generated from this function. Here is code of my web page. We also need to add a script reference to enable web service from client side. Here is all HTML code we have.
<form id="form1" runat="server">
<asp:ScriptManager ID="myScirptManger" runat="Server">
<Services>
<asp:ServiceReference Path="~/WebService/WsApplicationUser.asmx" />
</Services>
</asp:ScriptManager>

<div id="divUserList">
</div>
</form>
Now as we have not defined where we are going to call ‘GetUserList’ function so let’s call this function on windows onload event of javascript like following.
window.onload=GetUserList();
That’s it. Now let’s run it on browser to see whether it’s work or not and here is the output in browser as expected.

JSON string output in browser

That’s it. This was very basic example but you can crate your own JavaScript enabled grid from this and you can see possibilities are unlimited here. Stay tuned for more.. Happy programming..
Shout it
Share:

Distinct operator in Linq

Linq operator provides great flexibility and easy way of coding. Let’s again take one more example of distinct operator. As name suggest it will find the distinct elements from IEnumerable. Let’s take an example of array in console application and then we will again print array to see is it working or not. Below is the code for that. In this application I have integer array which contains duplicate elements and then I will apply distinct operator to this and then I will print again result of distinct operators to actually see whether its working or not.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Experiment
{
class Program
{
static void Main(string[] args)
{
int[] intArray = { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5 };
var uniqueIntegers = intArray.Distinct();
foreach (var uInteger in uniqueIntegers)
{
Console.WriteLine(uInteger);
}
Console.ReadKey();

}
}
}
Below is output as expected..
DisntictResult

That’s cool..Stay tuned for more.. Happy programming.
Technorati Tags: ,
Shout it
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews