Monday, July 7, 2008

Web User control in ASP.NET with AJAX


This is a application which shows that how to get chat data from server without refreshing the page. here in this application i have used ASP.NET framework 1.1 and with XMLHttpRequest object. i have created a Ascx control which you can use for your application to put a chat box at any position of your page.

There could be a better solution for chat box in web application but i found it good.

Downloads


How to use JSON in ASP.NET

JSON is JavaScript Object Notation. Which improve the code readability in java script code and also it help to create object code at client side in ASP.NET. Here you can define your properties and method.

Like

var VariableName=

{

“Property”: value, // Properties

“FunctionName1”:

function(){

//Function body.

},

“FunctionName2”:

function(){

//Function Body.

}

}

If we need any Customer object at client side then we can create like

Var CustomerJSON =

{

“Name”: “Mr Harry”,

“Age”: 23,

“Address”: “10000, Abc Blvd, Los Angeles”,

“Salary”: 300,

“IsRetired”:

function()

{

If (CustomerJSON.Age > 56)

return true;

}

}

You can directly add this JSON script in your ASP.NET page or you can register it by Register client script method of page.

Adding Java script in ASPNet page

Method -1 // In code behind (C# page)

Literal js = new Literal();

js.Text = "<script type='text/javascript' Src= 'CustomerJSON.js'></script>";

this.Header.Controls.Add(js);

Method -2 // in code behind (C# page)

StringBuilder sb = new StringBuilder();

sb.AppendLine("<script language=\"javascript\" type=\"text/javascript\">");

sb.AppendLine(Write your whole JSON code here.);

sb.AppendLine("</script>");

this.ClientScript.RegisterStartupScript(GetType(), "StartupScript", sb.ToString());

Method -3 // in aspx file

Add a new tag for

<script type='text/javascript' Src= 'CustomerJSON.js'></script>

Sunday, July 6, 2008

Code Snippet for Page Heading Comments

Introduction

This article/code snippet is use full in managing your code properly. like every class file should contain any comment about auther ,created date and other things. This Article contain two code snippet one is C# and other one is Vb.Net.

Background

Code Snippet are just xml file which we are using in your coding to display predefine code.

Using the code

every coding file (.cs or .vb) should contain the information about auther,created by namespace and other things.

Copy the attached file for following Locations
.
Location for Vb Code Snippet:
C:\Program Files\Microsoft Visual Studio 8\VB\Snippets\1033\application

Location for C# Code Snippet:
C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#

How to use The Code snippet.
For VB.NET
go to your any .vb page and right click at the top line of page.
then click on Insert Snippet. --> Select Application --> Select "#PageHeader"
then write down all the values mentioned at Snippet literals.
For C#
go to your any .cs page and right click at the top line of page.
then click on Insert Snippet. --> Select Visual C# --> Select "#PageHeader"
then write down all the values mentioned at Snippet literals.
if you still find any problem then feel free to talk with me.