2009-11-13 89 views

回答

1

MSDN

這是MSDN鏈接

if (!this.Page.ClientScript.IsClientScriptBlockRegistered(typeof(Page), "Utils")) 
     { 
      string UtilsScript = ResourceHelper.GetEmbeddedAssemblyResource("Utils.js"); 

      this.Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Utils", UtilsScript, true); 
     } 

我說上面的例子來幫助,

這裏我們測試腳本是否已經註冊(使用類型的我們註冊的dkey)從嵌入資源獲取腳本作爲字符串,然後註冊(最後一個參數爲true,告訴代碼呈現腳本標記)。

希望這有助於

P

+0

你能解釋冷杉和的RegisterClientScriptBlock第二arguemnt – 2009-11-13 20:36:13

+1

首先是一種「綁定」的腳本,在THI exampe頁,第二個是關鍵,這樣您就可以在使用Pag.ClientScript.IsClientScriptBlockRegistered(type,key)使用相同類型和用於註冊的密鑰來添加它(複雜的多控制環境)之前測試腳本是否存在。 – Pharabus 2009-11-13 20:40:27

1

將下拉列表的值移動到文本字段的示例。 ID參數是下拉列表和文本框的Object.ClientID屬性。

Private Sub RegisterClientDropDownToTextBox(ByVal functionName As String, ByVal dropDownId As String, ByVal textBoxId As String) 
    Dim javascriptFunction As String = "function " & functionName & "() {" & _ 
             "document.getElementById('" & textBoxId & "').value = document.getElementById('" & dropDownId & "').value;" & _ 
             "}" 
    Dim javascriptWireEvent As String = "document.getElementById('" & dropDownId & "').onclick = " & functionName & ";" 
    Me.ClientScript.RegisterClientScriptBlock(Me.GetType(), functionName & "_ScriptBlock", javascriptFunction, True) 
    Me.ClientScript.RegisterStartupScript(Me.GetType(), functionName & "_Startup", javascriptWireEvent, True) 
End Sub