I have got a similar thing working on one of my own pages. Try losing the single quotes from inside the alert statement and just pass the variable directly:
ClientScript.RegisterStartupScript(typeof(Page), "script", "alert(" + valid + ");", true);
EDIT: on second thought, this only seems to work if 'valid' contains a numeric value, not a string. See Pallavi's solution for the correct answer.