サーバー側でjavascriptを埋め込む

Dim cs As ClientScriptManager = Page.ClientScript

'jsファイルを読込
cs.RegisterClientScriptInclude("test1", "Scripts/test.js")

'スクリプトを実行
cs.RegisterClientScriptBlock(Me.GetType(), "test2", "alert('hello!ClientScriptBlock!')", True)

'スクリプトを実行
cs.RegisterStartupScript(Me.GetType(), "test3", "alert('hello!Startup!')", True)

スクリプトの実行順は、
RegisterClientScriptBlock → RegisterStartupScript
です。

色々と使い道ありそう(=゚ω゚)ノ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です