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
Doing or Raising Postback using __doPostBack() function from Javascript in Asp.Net
so that I add a self postback in the js.