Showing posts from May, 2010

Which path you have to use in your application?

What is Absolute path?

Absolute paths are called that because they refer to the very specific location, including the domain name. The absolute path to a Web element is also often referred to as the URL. For example, the absolute path to this Web page is:

What is Relative path?
Relative paths change depending upon what page the links are located on. Another word,A relative path is a path relative to the working directory of the user or application, so the full absolute path may not need to be given. There are several rules to creating a link using the relative path:
     links in the same directory as the page have no path information listed   filename     sub-directories are listed without any preceding slashes weekly/file-name    links up one directory are listed as   ../filenameLinking to a resource from a reusable control in different levels in your web app folder tree can be a tedious and not so obvious tas…

Accessing Master page functions from a content page

Accessing Master page functions from content page we must include a MasterType directive at the top of the Content page ASPX file:

<%@ MasterType virtualpath="~/DetailsMaster.master" %>

In DetailsMaster.master.cs page
public void SavePageData()
// function definition

After place the MasterType directive is in place in the Content page, then public functions in the Master page are available to the Content page code.

C# Code:
//Call the SavePageData function from the Master page

I hope it will helpfull for other developer.

Accessing Master page controls from a content page

Today I want to share with you how to use master page control from content page.
Suppose there is a Label on the Master page that we want to write to from the Content page.

1. We must include a MasterType directive at the top of the Content page ASPX file:

<%@ MasterType virtualpath="~/DetailsMaster.master" %>

2. We must include a public function in the Master page that returns a typed reference to the Label:

Public Function LabelReference() As Label
' Create a reference to an actual label on the page
LabelReference = lblDetailsItemName
End FunctionC#
public Label LabelReference()
// Create a reference to an actual label on the page
return lblDetailsItemName;
3. We can access the Label from the Content page using the Master syntax:

Master.LabelReference.Text = "Demo text";

Hope that it will help for developer.

Creating Object to a Class dynamically using Reflection

What is Reflection?

Reflection is the feature in .Net, which enables us to get some information about object in run time. That information contains data of the class. Also it can get the names of the methods that are inside the class and constructors of that object.

To write a C# .Net program which uses reflection, the program should use the namespace System.Reflection. To get type of the object, the typeof operator can be used. There is one more method GetType(). This also can be used for retrieving the type information of a class. The Operator typeof allow us to get class name of our object and GetType() method uses to get data about object's type.

One can use the Activator class for creating objects and then you can use reflection to call methods on the new instance, e.g.:

Example-1: C#
In this example simply show that how to create instance of a object dynamically,

using System;
using System.Runtime.Remoting;
using System.Reflection;
namespace ConsoleApplication3

How to get the CheckBoxlist Value using Javascript

A CheckBoxList renders as an HTML Table tag and does not have checked property. The child controls are CheckBoxes and do have the checked property.

There is no client-side "value" property in a CheckBoxList.
That is a server-side only property. You can only get the Text property of the ListItem (Item 1, Item 2, etc in this example).


<form id="form1" runat="server">
 <asp:CheckBoxList id="CheckBoxList1" runat="server">
  <asp:listitem Value="1">Item 1</asp:listitem>
  <asp:listitem Value="2">Item 2</asp:listitem>
  <asp:listitem Value="3">Item 3</asp:listitem>
 <input type="button" onclick="readCheckBoxList();" value="Read CheckBoxList" />
<script type="text/javascript">
function getCheckBoxListItemsChecked(elementId)
 var elementRef = document.getEle…

Url rewritng in 4.0

What is URL Routing?

URL routing was a capability we first introduced with ASP.NET 3.5 SP1, and which is already used within ASP.NET MVC applications to expose clean, SEO-friendly “web 2.0” URLs. URL routing lets you configure an application to accept request URLs that do not map to physical files. Instead, you can use routing to define URLs that are semantically meaningful to users and that can help with search-engine optimization (SEO).

For example, the URL for a traditional page that displays product categories might look like below:

Using the URL routing engine in ASP.NET 4 you can now configure the application to accept the following URL instead to render the same information:

With ASP.NET 4.0, URLs like above can now be mapped to both ASP.NET MVC Controller classes, as well as ASP.NET Web Forms based pages.
For more info please visits scottgu's article..

How to export Excel uisng HtmlForm(GridView) object in

Today I want to show you another way how to export Excel file from HtmlForm object. This is a serial post for How to export Excel file. Using HtmlForm object we should  use a Control which is rendering by HtmlTextWriter.

In this article, I use the GridView control. Here I provide a method where you pass a GridView control as parameter after that this method render this gridview control as a excel file from html object.


using System.Web.UI.HtmlControls 

public void ExportFromHtmlForm(GridView gvEmployee)
        HtmlForm form = new HtmlForm();
        string attachment = "attachment; filename=Employee.xls";
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        StringWriter stw = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);

Write As XML with .XLS extensions

Today I want to share with you how to write XML file as an excel file from DataTable. Here I  provide you a function where you just send a DataTable as a parameter and this function is responsible for generate the Excel file.

     public void ExportAsXMLtoXLS(DataTable dt)
        System.Data.DataTable dt = GetData();
        dt.TableName = "Employees";
        dt.WriteXml(Server.MapPath(".")+ @"\GenerateData.xls", XmlWriteMode.IgnoreSchema);

XML Parsing Error: no element found

Recently when I am working with web service which returns data as XML format. But unfortunately I always found that the page always show error : XML Parsing Error: no element found. Error does not contain specific information about the source of error.

The common reason for XML Parsing Error: no element found is missing closing tag for one or two html element, so I checked whole xml docs several times to make sure not miss any start and closing( or ) tags.


After searching for while I found that somehow ASP.NET treat the response of page as XML document and that’s why we receive XML Parsing Error: no element found error.
To solve this error I added a line
Response.ContentType = "text/HTML"to .cs page. This line tells ASP.NET runtime that response is HTML text and not XML.

How to DataTable export to Excel in

It is a very common question is forum and other forum that how to export DataTable to excel in
There are various ways to export data to excel, such as:

    1.    Write As XML with .XLS extensions
    2.    Render DataTable as Excel
    3.    Uisng HtmlForm object
    4.    Using VerifyRenderingInServerForm

Insha Allah, I will discuss all these export types gradually. Today I want to discuss here how to export DataTable to Excel. Its very simple ,I write down a method here just call it ana pass your DataTable as a parameter then this method generate a Excel file for you.

public void ExportDataTable(DataTable dt)
            string attachment = "attachment; filename=" + FileName.xls + "";
            HttpContext.Current.Response.AddHeader("content-disposition", attachment);
            HttpContext.Current.Response.ContentType = "application/";

Presentation @ Visual Studio 2010 community launch program

I have presented  " page life cycle" at Visual Studio 2010 community launch program.

You can download the presentations from this link. this rapidshare link collected from Omi Azad blog.

Visual Studio 2010 Community Launch Successfully!!

Visual Studio 2010 community launch program successfully held at 8 May 2010. Really its a great events those who are attends at that program. Trust me, those who are failed to attend this ceremony they missed a great event.
C# 4.0 Demystified presented by Tanzim bhai and Silverlight for Windows Mobile 7 using VS 2010 presented by Asif bhai make this events more fruitful specially for developers. And Omi bhai organized the whole ceremony very nicely.

How to get visitor's Country,longitude,latitude from IP address is

It is very common questions for new web developer how to get the client's country location to track the user.In various forum I

have faced this questions. So that today I want to share how to get client's country location,longitude,latitude,country code etc.
To get this you need to use a
free database which has IP to Location mapping
call a web service that does the same for you.
Using free web services is the easy way to get the location of the user based on its IP address. After goggling I have found the

following web service which provide this service absolutely free and that too without any complex interface to do the same.
The above website provides free IP Geolocation Web Service that returns data in three formats .

1. XML [Extended Markup Language]
2. CSV [Comma Separated Values]
3. JSON [JavaScript Object Notation]

Here I am explaining how to get the data in XML format.
It is very easy to use this web service,just send your ip addr…

How to get client's languages using

Recently I have fall in a situation that I need the clients language for fulfill the business requirement. I have found lots of resources about it. Today I want to share with you how to get client's language using

You can get the language from Browser using
or, You can also use this
Here HttpRequest.UserLanguages return a array of languages,so to retrieve the language you can use index of array like,
But there are some differents between them.HttpRequest.UserLanguages() returns a sorted array of language preferences, whereas the Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") returns a (comma-separated) string. In other words, HttpRequest.UserLanguages appears to take the value of Request.ServerVariables("HTTP_ACCEPT_LANGUAGE").

There are another way you can get it from CulturalInfo class.
CultureInfo ci = System.Threading.Thre…

Visual Studio 2010 Community Launch @Bangladesh

Date:Saturday, 08 May 2010 Time:10:30 - 14:00 Location:Auditorium, IDB Bhaban Street:Sher-E-Bangla Nagar Town/City:Dhaka, Bangladesh
MSDN Bangladesh Community cordially invites you to attend Visual Studio 2010 Community Launch.
Program Flow:
- Opening Speech - Omi Azad, Developer Evangelist, Microsoft Bangladesh Ltd.

- A Quick Look at Visual Studio 2010 - Irtiza A. Akhter, CTO, Micro Web Planet

- C# 4.0 Demystified - Tanzim Saqib, Software Designer, British Telecom

- ASP.Net page life cycle - Ahsan Murshed, Software Engineer, Cyber Jahan Ltd.

- Silverlight for Windows Mobile 7 using VS 2010 - Asif Huque, SaaS Developer, British Telecom

- T Shirt & CD Distribution - Lunch and Closing