The code you are using I used that one a long time back and it gave me the same error.Then I changed the style of the code..
What I did was keep the Javascript separately(client end code) from the server side coding..I placed the server side coding in the code behind..(aspx.vb) and drag and dropped the controls like textbox and that automatically created my
"Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox"
and solved the issue..
It was a long time back and I remember I did something like this..My answer might not solve your issue but you can do something like this and be sure it works..
Hope it helps...