I followed this tutorial to create a action which pass value to the dialog windows then execute the server side code.
It all works but the problem is user has to click a button or something to trigger a post back. then the arg value can be loaded because the js code is executed after server side code.
I then read this postback tutorial
so that I add a self postback in the js.