January 2007 - Posts

New Dress Code in my company ... Yes!

Just received the latest news from my company's HR.

This Friday onwards all of the developers in Mesiniaga willl wear smart casual. Can wear T-Shirts with collars. But cannot wear jeans and sport shoes. Probably we have to push harder next year 2008.

Yes ... I am so happy ... No need to buy new clothes (coz long sleeves are not cheap).

Posted by chuawenching with no comments

Browser Compatibility Problems - OnClick not functioning in FireFox but okay in IE

Just to update you guys, assuming you have the code below:

< ... onClick="AddNumbers(1);"  ... />

Most of the time this is how you do it? It works fine in IE. Who cares right? When you try on FireFox, it doesn't work.

So make sure you always return false like the code below in order for all browsers to work.

< ... onClick="AddNumbers(1); return false;" .... />

Have fun.

Posted by chuawenching with 1 comment(s)
Filed under:

Browser Compatibility Problems - CSS Cursor

Just to update you guys on what I found, cursor: hand; works fine on Windows browsers but not on Safari and Firefox. No wonder it is not working at the first place. I thought CSS should be standard. Probably too many CSS standards.

Check out this diagram from this site http://www.quirksmode.org/css/cursor.html

It is not so easy to have a web application to support on so many browsers :(

Posted by chuawenching with no comments
Filed under:

Crazy about community

Count 1 ar 2 ar 3

Existing communities:

1. MIND

2. INETA Academics Malaysia

New communities

1. Mesiniaga Private Community. Only my company's Microsoft Team developers.

2. Celcom Power Circle - well not leading it but a forum moderator helping out on .NET stuff. Celcom  is one the big 3 telcos in Malaysia. Celcom Power Circle buils a platform for .NET Developers to consume mobile services. Cool stuff. But it is a private community.

What else more to come this year? I really enjoy doing community.

Posted by chuawenching with no comments

MIND Committee 2007

A team of young and talented professionals who drive this MIND community. You will be suprised that the other 3 are younger than me. But they did an excellent job potraying their passion in community.

It is not necessary we need people who are much older to lead the community. Probably younger people has more energies.

Furthremore MIND is acquiring a lot of sponsors to the community. Hope we can drive all the Malaysian's Microsoft Developers to this community.

Posted by chuawenching with no comments

UNIMAS Trip was fantastic

I was busy after I came back from UNIMAS, Sarawak. UNIMAS is the biggest university in Malaysia. Nice place.

It was a fantastic event. Even though there were only 50 ++ students but I was happy that they loved my 2nd session.

1. Software Migration: From ASP.NET 1.1 to 2.0

2. A Journey of a Software Developer

I am looking forward to present my 2nd slides to other tertiary education in Malaysia and hopefully out of Malaysia.

Below are 2 pictures takes in UNIMAS.

 

Posted by chuawenching with no comments

Session State Management in Project: Migrate In-Proc to Out-Proc State Server

Session State Management in Project

Migrate In-Proc to Out-Proc State Server

By Chua Wen Ching, January 29, 2007

 

Overview

 

There are a lot of reasons why an in-proc session state will lost when a web application is running. To name a few:

 

  1. Changes to bin folder, web.config and machine.config
  2. Changes to other file folders. This is stricter in .NET 2.0 than .NET 1.1.
  3. Somewhere in the code caused a JIT. Code does not catch the exceptions properly.
  4. ASP.NET Web Application restarts.
  5. AppDomain recycles
  6. Session timeout too short

 

In order to illustrate the details, I had drawn some visual diagrams to aid my explanations. I did not draw in very detail, but hope it would assists in your understanding.

 

Problem

 

 

Figure 1 

 

By default, an AppDomain will host the ASP.NET Web Application. When you use In-Proc session, basically this session exists within the scope of the web application.

 

 

Figure 2

 

Assuming when you run your web application, you encounter a Just in Time Exception (JIT) and it is not handled properly. The common JIT error is System.NullReferenceException.

 

Take note, my diagram focuses on web application which restarts because of an unhandled exception. I did not draw on AppDomain.

 

 

Figure 3 

 

When your application restarts basically it will lose the session and will generate a new session when the user logins again.

 

It is possible to happen as when you configure the web application to use In-Proc (or In-Process), it will store the session in the server’s memory.

 

Solution

 

I will recommend every developers who want to use Session State Management to consider Out-Process. Honestly speaking every session techniques (In-Process and Out-Process) has its own pros and cons.

 

Based on my researches, it was recommended to always stick to Out-Process: State Server for all project development. If there is a need to change to In-Process, it will be easier to migrate.

 

Out-Process session is divided into 2 types:

  1. State Server (windows service)
  2. SQL Server (stored in the database as tables)

 

The major issue with Out-Process is it is very slow compare to In-Process. The reason it is slower than In-Process as there are serialization / de-serialization costs. By passing the .NET Data Types like (string, int) will not cost any overhead. But if you declare a class like (Person, ArrayList) and pass into the session it needs to be serialized. In terms of reliability, Out-Process wins over In-Process.

 

 

Figure 4

 

When you use Out-Process for your session, basically it is stored in either Windows Service or SQL Server.

 

 

Figure 5

 

When you encounter a Just In Time (JIT) Exception, your web application will recycle. However there is no effect to the windows service or SQL Server.

 

Furthermore you can run your web application in a web server box and the Session State Service in another server.

 

How-To

 

Overview

 

There will be 2 sections on this. First explains the steps by steps and the 2nd one is the enhancement over your existing In-Process codes to Out-Process.

 

Step by Step

 

  1. You need to run the aspnet_state windows service. There are 2 ways to achieve this.
    1. Go to Start à Run and type “net start aspnet_state” (excludes the double quotes) OR
    2. Go to Start à Run and type “services.msc”. Then look for ASP.NET State Service and starts it.

 

New Enhancements

 

Assuming you has a Framework class library. Within this class library, you have a SessionName class. Below is a snippet of the SessionName.

 

Existing In-Process SessionName reusable class

 

public class SessionName : Hashtable

{

            public const string SESSION_MODULE = “SESSION_MODULE”;

            // other sessions declarations here

}

 

 

  1. Set the SessionState in web.config to support StateServer instead of In-Proc.

 

Before

 

<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=server;user id=sa;password=r0ti" cookieless="false" timeout="500"/>

 

After

 

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="false" timeout="20"/>

 

  1. In Framework Class Library, modify the SessionName class file to support serialization.

 

Before

 

            public class SessionName : Hashtable

            {

            }

 

After

 

[Serializable]

            public class SessionName : Hashtable

            {

}

 

  1. In the same class file SessionName, you have to place support for deserialization. It is not as straightforward as by default SessionName inherits from Hashtable. In Hashtable, the constructor for de-serialization is protected. You need to override this constructor and make it public.

 

New Changes

 

[Serializable]

            public class SessionName : Hashtable

            {

                        // Existing codes

             

                        // Add this code

                        public SessionName(SerializationInfo info, StreamingContext context)

                                     : base(info, context) { }

}

 

Conclusion

 

Hope this document is able to grasp an understanding on these changes for your project. Have a nice day.

Posted by chuawenching with no comments

Waiting to go to Sarawak

I am now in KLIA airport and wating for my MAS flight to Kuching, Sarawak. It is a domestic air flight and it is my 1st INETA Academic Initiatives for year 2007. It will be an exciting one.

Apparently, my accomodation and air flight are fully sponsored by the university. Thanks. I am looking forward to speak in all IT Universities / Colleges in Malaysia this year to share my knowledge.

I have much to learn from the industry, but it does not stop me to share on what I have learned in the past? I really learn a lot and I know one day I can be a better leader and developer. Ok stop with my nagging.

It is quite cold here and I am really excited. I never been to Sarawak even though I am a Malaysia. Will update my blog when I am back from Kuching. Lucky I have a few Microsoft friends there. Yes :)

Posted by chuawenching with no comments

MIND Gathering January 2007 Updates

Wow. I was very happy that a total of 55 people turned up for my session. As you understand it was a weekend, and it was hard to get so many people in Malaysia to attend our event. Well we broke our record in January 2006 with 140 people and full house. I am looking forward to break record again this year.

Thanks to all the speakers who attended my sessions. Thanks to Microsoft Malaysia, INETA and O'Reilly for the support.

Posted by chuawenching with no comments

My community initiatives on January 2007

What is next for my community initiatives on January 2007?

a) MIND Gathering Jan 13, 2007. There will be 4 presentations + 1 round table. The longest session ever in MIND history. Check it out http://www.mind.com.my I am not speaking but I am coordinating it.

b) UNIMAS, Sarawak Jan 16/17 2007. Will have a joint event between INETA and Microsoft Malaysia Academics. My trip is fully sponsored by UNIMAS. Speaking on ASP.NET migrations and general tips to be a better software developer. I will also help to craft ideas for Imagine Cup 2007.

Cheers.

Posted by chuawenching with no comments

ASP.NET 2.0 Master Page - Preferred way to call reference control id using javascript

Just to share a tip today, there is a number of ways to call reference of a server control on a web form. Before that, how do you call the reference id of the control? If you read my blog earlier, you can use developer toolbar or right click on the webform and see the view source.

 

I will illustrate the example based on MasterPage.

 

Assuming you have a JavaScript that need to check the value of the txtDate and do some internal validation, you can use this way below to get the reference of it:

 

aspnetForm.ctl00$ContentPlaceHolder1$Child1$UclCalendar1$txtDate.value

 

OR

 

aspnetForm.ctl00_ContentPlaceHolder1_Child1$UclCalendar1_txtDate.value

 

Why use aspnetForm in front?

Why not form1 or form_name or MainForm assuming that in the MasterPage form you have a code like this?

 

<form id="MainForm" runat="server">

    <div>

 

The reason if when you use MasterPage, the id of the form is replaced to aspnetForm. This indicates the usage of MasterPage in the web form. That is why you need to pass in the aspnetForm.ct100… or else you can get an invalid javascript object.

 

But thinking it a while, what you have done is definitely functional? But is it cross browser?

 

I will recommend you all to consider using this after facing some issues some time:

 

document.getElementById("ctl00_ContentPlaceHolder1_Child1_UclCalendar1_txtDate").value

 

Use document.getElementById.

 

document.getElementById() is supported by every JavaScript supporting browser released since 1998.

 

There is definitely some debate on this, but I believe it will work great on most modern browsers like FireFox and Internet Explorer.

Posted by chuawenching with 1 comment(s)

Building Security Awareness in Web Application #2: Why JavaScript is so powerful?

If you have seen my 1st part, below is yet another interesting javascript which you can manipulate the objects on client mode :) Cool stuff. Nothing to do with security yet :)

Try www.microsoft.com and then try the script below.

"javascript" :R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval('A()',5); void(0);

// remove the double quotes in between javascript and the spacing between " :

Have fun.

Posted by chuawenching with no comments

ASP.NET Disable HTML Controls on the Fly

Assuming you have a HTML control in your ASP.NET web form, and you want to disable that html button depends on the user authorization, so how can you achieve it?

 

You cannot use FindControl or call the button ID directly as I believe that HTML control does not do postback.

 

So you just have to play around with JavaScript and Page.ClientScript.RegisterStartupScript

 

Example:

 

// Put this in between <head>

<script language="javascript">   

        <!--        

            function DisabledButton1()

            {

                form_name.Button1.disabled = true;

               

                return (true);

            }

        -->

</script>

 

// Put this in the body

 

<input id="Button1" type="button" value="button" />

 

// Put this in Page_Load event

// Have to use JavaScript as html control doesn't post back

        Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", " <javascript> : DisabledButton1()", true);

 

*remove the < > and the spacing between javascript ... my blog blocks it

 

Have fun J

Posted by chuawenching with 6 comment(s)