To write javascript to the document you can use
Code:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "some_key", "alert('Hello');", true);
MSDN: The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised
Or you can use
Code:
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "some_key", "alert('Hello');", true);
MSDN: The RegisterClientScriptBlock method adds a script block to the top of the rendered page.
The last option I know, is to use a literal
Html
Code:
<body>
...
some text and controls
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
some more text
</body>
CodeBehind
Code:
Literal1.Text = "<script type='text/javascript'>alert('Hello');</script>";