.Text is a wrapper around a SimpleFuture. It is a two step procedure:
inpUsername.Text = inpUsername.Text.Trim
The: inpUsername.Text.Trim gets the text from the browser and trims it.
The: inpUsername.Text 'prepares' to set the text for the browser (but does nothing at this point in the browser)
So when you call inpUsername.Text again:
Log ("trim ul: " & inpUsername.Text.Length & " trim pl: " & inpPassword.Text.Length)
you're actually asking the browser again, what do you have? --> so it returns the original text from the browser.
Only when a .refresh happens, the actual 'trim' version is pushed to the server.