Read, With the Name of Your Lord Who Created

Posts Tagged ‘C#’

Pagination in ASP.NET

Posted by triaslama on May 18, 2008

ASP.NET has DataGrid control, and datagrid control has build in support for pagination. What I do in this post is just something like datagrid pagination, but I add two buttons each of them to navigate to previous and next page respectively.

I use ListOfPage class to produce list of page number, you can see more on this class in my previous post here. For simplicity I use array of string as data source, in more common scenario maybe we use data from database, represent it in DataTable then use the DataTable as a data source.

I do the manual pagination in ASP.NET with code behind style. There is I put the code that produce list of page in a separate file (I named it ManualPagination.aspx.cs). The presentation page laid in ManualPagination.aspx which refers to our code behind file.

Let’s start with presentation page! It’s quite simple, this is the source code (ManualPagination.aspx):

    <%@ Page Language=”C#” CodeFile=”ManualPagination.aspx.cs” Inherits=”ManualPagination.CodeBehindClass” %><html>
    <title>Manual Pagination in ASP.NET</title>
    <style type=”text/css”>
    <form runat=”server”>
    <asp:Label id=”lblPresentation” runat=”server” />
    <p />
    <asp:Button id=”btnPrev” text=”Prev” onclick=”btnPrev_Click” runat=”server” />

    <asp:Label id=”lblPages” runat=”server” />

    <asp:Button id=”btnNext” text=”Next” onclick=”btnNext_Click” runat=”server” />


One of the important portion of our presentation page relies on the following code:

Read the rest of this entry »


Posted in ASP.NET, C#, Javascript | Tagged: , , , , , , | Leave a Comment »

Page Number Generator

Posted by triaslama on May 13, 2008

One of the way to prevent show all of data in one page is pagination. Pagination is the process organizing information in pages. For instance, the information appear in a web pages is paginated such that appear 10 lines for every page.
Pagination can be a cool way to manage the looks and feels of information. Because too many tabular data often tedious, hard, or we maybe easily miss something if all of information dropped in a page.

So, what is needed to do pagination? I think one of the most apparent is a list of page! I have write a program (a simple program) in C# that generates page number. The input parameters is current page, number of rows in a page, and the amount of rows.

Output of this progam is array of integer, every number reflected page number being showed. And this is the listing of program:

Read the rest of this entry »

Posted in C#, Programming | Tagged: , , , | 4 Comments »

Simple Date Time Format in .NET

Posted by triaslama on December 10, 2007

DateTime format it’s a simple but interesting enough to get my attention. The problem begin when I must work with the DateTime type and I encountered several exception that raised because of date time formatting.

For explanatory purpose here I give a brief introduction on date time formatting in .NET platform:

Format Specifier



Displays the specified date of the month (short form).


Displays the specified date of the month (long form).


Displays the specified date of the month (measured the number between 1 and 31 -inclusive-). If the number is a single digit only, then the formatting preceding with zero number.


Displays abbreviated name of the specified date.

dddd (or more)

Displays full name of the specified date.


Displays the specified month (two digits).


Displays abbreviated name of the specified month.

MMMM (or more)

Displays full name of the specified month.


Displays specified date and time (short form).


Displays specified date and time (long form, time format excluding second digits).


Displays specified date and time (long form, time format including second digits).


Displays two digits number of the specified year, the first two digits are omitted.


Displays the specified year.


Displays hour for the specified DateTime in am/pm format.


Displays hour for the specified DateTime in 24 hours format.


Displays minute for the specified DateTime (range: 0-59).


Displays second for the specified DateTime (range: 0-59).

Please refers to the .NET documentation for the more complete date time formatting, I exclude several formats here.

The above formatting is done using DateTime.ToString() method. ToString method from DateTime class has four overloads. One of them receives string as a parameter and then we can do date time formatting like the following (written in C#):

using System;

namespace Learning_Materials

class SimpleDateTimeFormats


static void Main(string[] args)


DateTime date = DateTime.Now;

// print out the date time using default format


// otherwise, specify the other formats


Console.WriteLine(date.ToString(“dd/MM/yyyy”)); // Indonesian format (date/month/year).

Console.WriteLine(date.ToString(“dd-MMMM-yyyy hh:mm:ss”)); // Indonesian format (date-month(fullname)- year hour(24 hours):minutes:seconds)

Console.WriteLine(date.ToString(“MM/dd/yyyy”)); // en-us format (month/date/year).

Console.WriteLine(date.ToString(“MMMM dd, yyyy HH:mm:ss”)); // en-us format (month date, year hours(am/pm format):minutes:seconds).





Here we go, sometimes missing the date time format can be so sucks. I ever do this mistake when I must insert user input in string format to the MS SQL Server database. the input was in date/month/year format (standard format for Indonesian date) but the SQL Server format was month/date/year, finally the exception happen.

Hopefully that I will found more interesting things in my coding experience and I can learn more from my mistakes (smile face). Regards and see you later.

Tri Sugiyantowo (triaslama)


Posted in .NET | Tagged: , , , , | 68 Comments »

Populate Web Part Melalui Share Point 2007

Posted by triaslama on November 28, 2007

Setalah pada artikel sebelumnya telah dibahas tentang bagaimana langkah – langkah konfigurasi yang diperlukan untuk membuat web part dengan visual studio 2005 dan share point 2007, maka pada artikel ini akan dibahas tentang langkah – langkah yang diperlukan untuk menyiapkan web part yang telah dibuat agar dapat ditempatkan pada suatu halaman web ASP.NET.
Untuk dapat men-deploy / mem-populate web part, kita harus melakukan login sebagai administrator. Selanjutnya ketikkan alamat server pada browser, masukkan user name sehingga akan memunculkan halaman dengan menu Site Actions pada bagian kanan atas.

Untuk mem-populate suatu web part, klik bagian Site Actions > Site Settings > Modify All Settings. Hal ini ditunjukkan pada gambar berikut:

Modif All Settings

Setelah itu akan muncul halaman Site Settings sebagai berikut:


Pada halaman Site Settings tersebut pilih Galleries → Web Parts (ditunjukkan oleh anak panah pada gambar diatas).

Setelah link Web Parts tersebut kita pilih maka selanjutnya kita akan memasuki halaman Web Part Gallery. Pada halaman tersebut akan terlihat beberapa web part yang telah dibuat, untuk membuat web part baru dari kode program yang kita tulis, klik tombol New seperti ditunjukkan pada gambar berikut ini:


Setelah tombol New di-klik, selanjutnya kita akan memasuki halaman Web Part Gallery: New Web Parts. Pada halaman ini kita dapat menambahkan web part baru yang selanjutnya web part yang ditambahkan tersebut akan ditampilkan pada halaman Web Part Gallery.

Untuk menambahkan satu atau lebih web part baru beri check list pada check box yang tersedia pada samping kiri dari web part yang akan ditambahkan selanjutnya klik tombol Populate Gallery. Hal ini dicontohkan pada gambar berikut ini:



Setelah tombol Populate Gallery di-klik maka proses populate web part telah selesai.

Note: web part yang terdapat pada halaman Web Part Gallery: New Web Parts akan bertambah setiap kali kita melakukan build melalui Visual Studio yang output path-nya telah diarahkan ke lokasi drive server. Selanjutnya web part yang kita buat akan diberi nama dengan nama yang terdapat pada text box File Name, secara default web part akan diberi nama sama dengan nama kelas yang kita buat. Ganti nama default yang diberikan jika kita menginginkan nama yang lain. Untuk mengganti (meng-override) web part yang pernah kita populate sebelumnya beri check list pada check box Overwrite if file already exists?


Posted in SharePoint | Tagged: , , , , , , | Leave a Comment »

Pembuatan Web Part Menggunakan Visual Studio 2005 Dan Share Point 2007

Posted by triaslama on November 27, 2007

Pembuatan dan Konfigurasi Web Part

Untuk membuat web part pada share point 2007 menggunakan Visual Studio 2005 diperlukan beberapa langkah konfigurasi sederhana. Pertama kali buat project baru pada Visual Studio 2005, pilih Create Project, selanjutnya pada Visual Studio installed templates pilih Class Library. Berikut ini langkah – langkah yang harus dilakukan untuk men-deploy web part melalui Visual Studio 2005:

  1. Pada file AssemblyInfo.cs, tambahkan code berikut:


Assembly ini terletak di namespace System.Security, jadi pada bagian deklarasi namespace file AssemblyInfo.cs tambahkan namespace tersebut seperti contoh berikut:

using System.Reflection;

using System.Runtime.CompilerServices;

using System.Runtime.InteropServices;

using System.Security;

2. Pada bagian ‘Solution Explorer’ Visual Studio klik kanan Properties > Open, sehingga akan muncul jendela properties. Pada bagian Build pilih output path dengan mengarahkannya pada drive server, hal ini ditunjukkan pada gambar berikut ini:


Dengan mengarahkan build pada output path tersebut berarti setiap kali build atau compile untuk program yang kita buat maka proses build tersebut akan dilakukan di-drive yang disebukan pada output path tersebut (output path pada gambar diatas adalah drive tempat dimana share point 2007 berada).

3. Masih pada jendela Properties, pada tab Signing pilih checkbox untuk membuat suatu key assembly dan beri nama key tersebut, hal ini dicontohkan gambar berikut:


4. Langkah selanjutnya adalah mendaftarkan assembly yang kita buat pada file web.config. File ini terletak pada virtual directory server (dalam contoh ini file web.config terletak pada drive: Z:\Inetpub\wwwroot\wss \VirtualDirectories\80). Pada web.config tambahkan beberapa informasi mengenai assembly yang dihasilkan dari kode yang telah kita tulis. Informasi – informasi tersebut meliputi: nama assembly, PublicKeyToken, namespace, dll.


Note: untuk memperoleh informasi mengenai assembly yang dihasilkan oleh program (meliputi nama assembly, versi, serta PublicKeyToken) gunakan suatu tools, misalnya Lutz Roeder’s .NET Reflector. Hal ini dicontohkan melalui gambar berikut ini:



Jika langkah – langkah konfigurasi diatas telah dilakukan dengan benar, maka selanjutnya kita dapat men-deploy web part yang kita buat pada halaman web ASP.NET.

Note: kesalahan mengubah web.config dapat mengakibatkan keseluruhan aplikasi tidak berjalan, jadi selalu siapkan back-up web.config & selalu hati – hati dalam mengubah web.config.

Berikut ini contoh elemen yang harus ditambahkan dalam web.config untuk men-deploy suatu web part:


<SafeControl Assembly=”KebijakanProgramDanKegiatanDepkeu, Version=, Culture=neutral, PublicKeyToken=f1a7843868cd0ddf” Namespace=”KebijakanProgramDanKegiatanDepkeu” TypeName=”*” Safe=”True” AllowRemoteDesigner=”True” />



Jadi intinya perlu dilakukan penambahan tag <SafeControls /> yang berisikan beberapa informasi mengenai assembly yang akan di-deploy sebagai web part.

Pada bagian selanjutnya -Insya Allah- akan dilakukan pembahasan mengenai bagaimana mem-populate suatu web part pada halaman ASP.NET. Sampai jumpa lagi.






Posted in SharePoint | Tagged: , , , , , , , | Leave a Comment »

Pengenalan Web Part

Posted by triaslama on November 5, 2007

Ini adalah pengalaman yang saya peroleh baru – baru ini, berkaitan dengan dengan penempatan saya di proyek departemen keuangan. Sebelumnya saya ucapkan terima kasih kepada temen – temen se-tim atas bantuannya selama ini (mas Aan, mas Reno, Anthony-kalau ada yg keliru tolong koreksi ya.-).

Web part merupakan suatu library (file dengan ekstensi *.dll), yang dapat dipasang/ ditempatkan pada halaman web ASP.NET. Jadi suatu webpart akan menempati wilayah atau bagian tertentu dari halaman web ASP.NET. Konsekuensi dari hal ini adalah penggunaan web part dapat meningkatkan reusability, misalnya web part A dapat dipasang pada halaman web_A dan halaman web_B dan juga halaman web_A dapat terdiri lebih dari satu web part misalnya halaman web_A terdiri dari web part A dan web part B.

Dalam .NET, untuk bisa menjadi suatu web part maka suatu kelas harus mewarisi dari kelas yang bernama WebPart(kelas ini terdapat dalam namespace System.Web.UI.WebControls.WebParts). Listing sederhananya dapat kita lihat dalam cuplikan kode berikut ini:

public class FirstWebPart : System.Web.UI.WebControls.WebParts.WebPart

Sedangkan berikut ini syntaks yang diperlukan untuk membuat suatu program ‘hello world’ dari suatu web part:

using System;
using System.Web;
using System.Web.UI.WebControls.WebParts;

namespace TestWebPart
    public class FirstWebPart : System.Web.UI.WebControls.WebParts.WebPart

    // mengganti implementasi method Render dari kelas WebPart
       protected override void Render(HtmlTextWriter writer)
           writer.Write("Hello, World...!!!");

Tapi yang harus diperhatikan karena kelas ini dimaksudkan sebagai library maka dia tidak dapat dijalankan secara langsung, harus ada suatu halaman web yang menggunakannya dan halaman web tersebut dipanggil lewat browser barulah kita akan melihat hasilnya.
Masih banyak hal yang harus diperhatikan dalam kaitannya dengan penggunaan web part, diantaranya bagaimana menggunakannya melalui halaman web dan juga konfigurasi yang diperlukan. Sampai jumpa lagi

Posted in .NET | Tagged: , , , , , | Leave a Comment »

.NET Remoting, a First Maneuver

Posted by triaslama on February 21, 2007

After my previous simple article in introduction and preliminary of .NET remoting, now let’s get coding, cause quite often that the code makes us more understand about some concepts than a thousand of words.

We will make a simple, cannonical program, call this ‘hello world’ program that executed remotely, the program consist of, at least, three portions, server, remotable object, and client.

The server and client communicate through a channel, and when a request for a remote object come the proxy is created, this proxy will acts as if remote object.

An important thing here that we will try not distributed all of the implementation, but give the clients an interface (or abstract base class that in some cases behaves like interface). So here we define an interface for the remote object, the code will look like this :

// IRemoteObject.cs

using System;

namespace SimpleLibrary

public interface IRemoteObject
string HelloWorld();

Compile the above program : csc /t:library IRemoteObject.cs
Put IRemoteObject.cs in a folder and named this folder as ‘Server’.
Next step is let’s write the implementation of IRemoteObject, the important note here is that implementation will reside in server, because distributes the full implementation are often bad ideas, why? first, that make the aims of distributed programming futile, second, distributes full implementation will take us in more problem of versioning, third distribute full library implementation make possible to disassembly the library using disassembler tools (ie. ildasm), and more reasons that ensure us to give the client program only what they need, I mean as much as possible give the interfaces not implementations.
The implementation is quite simple, of course because this is a ‘hello world’ program, remember this is first maneuver :

// SimpleLibrary.cs

using System;

namespace SimpleLibrary
public class RemoteObject : MarshalByRefObject, IRemoteObject
public RemoteObject()

public string HelloWorld()
return “Hello, world!!!”;

Compile the above program : csc /t:library SimpleLibrary.cs

Next lets build an host application for that program :

//Puts the following code in folder that was created (Server), and named Server.cs //csc /r:IRemoteObject.dll,SimpleLibrary.dll Server.cs

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using SimpleLibrary;

namespace ServerSide
class Server
static void Main()
HttpChannel chnl = new HttpChannel(8888);

// keeps the server running until key press


Now, the next is build the client that will consume our remote object, for simplicity we will build the client as console application, but we can build the client on the other form (ie. WinForms, with some modifications). Create a folder and named it Client, put the Client.cs (code that will consume remote object). But before go through the client code we need to copy the IRemoteObjcet.dll to the Client folder.

// Client.cs [csc /r:IRemoteObject.dll Client.cs]

using System;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Http;

using SimpleLibrary;

namespace ClientSide


class Client

static void Main()


IRemoteObject remObj = (IRemoteObject) Activator.GetObject(typeof(IRemoteObject), “http://localhost:8888/first.rem&#8221;);




To run the programs, open a command prompt that point to the location where the server.exe resides (in the above example inside Server folder), simply write Server.exe and run it.

Open the other command prompt that point to the location of client.exe (in example in Client folder), write client.exe and run it.

The important thing to be noted here is that the server must run first before the client, or we will get an exception.

Well, the simple ‘hello world’ remoting program has accomplished…

Posted in .NET, Programming | Tagged: , , , , | 4 Comments »

Basic .NET Remoting Stuffs

Posted by triaslama on February 14, 2007

Remoting can be thinked in three building blocks. Here are the brief explanations each of them.

1. Remotable objects, this is object that can be called across application domain boundaries, the most common object are not remotable, we must make an object remotable by value or by reference. By value object can be achieved by marked them as Serializable (with [Serializable] attribute), or that object implements ISerializable. By reference can be achieved by derived them from MarshalByRefObject.

2. Host for remotable objects, the host application in .NET remoting can be vary, the host can be console applications, windows applications, windows service, or ASP.Net applications. The host applications can be thinked as listener program that controls the access to remotable objects and waiting for client requests.

3. Client applications, the clients can be vary, that is the programs that consumes the remotable objects.

In much situations the .net remoting consists of these three things. How the simple scenario of remoting works? Wait for the next of my posts, Insya Allah.

Posted in .NET, Programming | Tagged: , , , , | Leave a Comment »

Another Interesting Stuff : .NET Remoting

Posted by triaslama on February 3, 2007


.NET Remoting is a kind of Inter Process Communication (IPC), that intended to communicate among processes on .net environment. This works much easily in .net, the scenario is like this, we have a listener program, and a client that will initiate communication.

Communication in .net remoting accomplished through what is called a proxy. A proxy is an object that impersonates the remote object (that is object in another process), so the client will behaves as if they have the remote object, here I called ‘impersonates’ because the client doesn’t really has the remote object, the client could be only has the metadata or the interfaces but not implementations.

The concepts of .net remoting actually similar with Web Services, but they both not actually same, .net remoting is more intended to communicate among .net processes, processes that communicate located on different Application domains (can be in the same computer, or on separate computer that connected through network).

Yeah, the article above is the first sight on .net remoting, and I hope can get more interesting stuffs…

Posted in .NET, Programming | Tagged: , , , , | Leave a Comment »