2012-05-08 40 views
0

我在我的頁面中有java腳本,我想從vb.net代碼中調用它,並且不想調用它(onload或onclick或任何類似的事件),但我想從函數調用它循環。所以它會運行一個以上的時間如何從asp.net後面的代碼調用javascript?

+1

?! ...你有一個代碼縮減/例子你想做什麼? – creativeby

+4

像你這樣的領導者不理解客戶端和服務器端代碼之間的區別。 – ThiefMaster

+1

這是不可能的。代碼後面=服務器端,JavaScript =客戶端。 –

回答

3

你需要做的是這樣的:

' Define the name and type of the client scripts on the page. 
    Dim csname1 As [String] = "PopupScript" 
    Dim cstype As Type = Me.[GetType]() 

    ' Get a ClientScriptManager reference from the Page class. 
    Dim cs As ClientScriptManager = Page.ClientScript 

    ' Check to see if the startup script is already registered. 
    If Not cs.IsStartupScriptRegistered(cstype, csname1) Then 
     Dim cstext1 As New StringBuilder() 
     cstext1.Append("<script type=text/javascript> getval('elementid') </") 'Your javascript function 
     cstext1.Append("script>") 

     cs.RegisterStartupScript(cstype, csname1, cstext1.ToString()) 
    End If 

Source.

+1

誰低估了這個沒有理由這樣做。這正是OP所要求的,它肯定會起作用。 – Icarus

+0

謝謝,但我可以直接在我的函數中使用它在代碼後面運行它或將它放在頁面加載中僅註冊它 –

相關問題