If you know, before sending the response to the client, that you're going to set the readonly attribute then you can do this with server side code. If it needs to change according to the user's input, without sending another post to the server, then this will need to be done on the client.
If you need to do this on the client side, let us know so we can move this thread to the HTML/Javascript forum.