ScriptManager.ScriptResourceMapping
(Path
とDebugPath
属性を利用するために)使用して参照したいクライアント側スクリプトを使用してカスタムコントロールを構築しています。
カスタムコントロールを他のプロジェクトに簡単に移植したい-つまり、コードビハインドファイルをドラッグアンドドロップしたい(そして最終的にはコントロールを別のDLLにしたいが、今のところドラッグアンドドロップで十分だ)。したがって、(1)クライアントスクリプトを埋め込みリソースとして使用したり、(2)で参照したり、(3)でを使用したりすることは避けたいWebResource
とAssemblyInfo
思いScriptManager.ScriptResourceMapping.AddDefinition
ますglobal.asax
。
簡単に言えば、スクリプト管理コードをカスタムコントロールのコードだけに含めることはできますか?
現時点では、アセンブリにスクリプト参照が見つからないというエラーが表示され、間違ったアセンブリを設定していると思います。
私のカスタムコントロールコードは次のとおりです。
Public Class MyControl
Inherits System.Web.UI.LiteralControl
Implements ISectionControl, IScriptControl
Private _scriptReference As ScriptReference
Public Sub New()
' Add the resource mapping
ScriptManager.ScriptResourceMapping.AddDefinition("MyControlScript", New ScriptResourceDefinition With {
.ResourceAssembly = System.Reflection.Assembly.GetExecutingAssembly,
.ResourceName = "MyControlScript.js",
.Path = "Path.To.MyControlScript.minimised.js",
.DebugPath = "Path.To.MyControlScript.original.js"
})
' Set the script reference
_scriptReference = New ScriptReference("MyControlScript.js", Assembly.GetExecutingAssembly.FullName)
End Sub
Protected Overrides Sub OnPreRender(e As System.EventArgs)
MyBase.OnPreRender(e)
' Register the script
ScriptManager.GetCurrent(Page).RegisterScriptControl(Of MyControl)(Me)
' Some code to set the Text of the literal control
' ...
End Sub
Public Function GetScriptDescriptors() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptDescriptor) Implements System.Web.UI.IScriptControl.GetScriptDescriptors
Return New ScriptDescriptor() {}
End Function
Public Function GetScriptReferences() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptReference) Implements System.Web.UI.IScriptControl.GetScriptReferences
Return New ScriptReference() {_scriptReference}
End Function
End Class
質問が理にかなっていることを願っています。時間を割いて読んでいただきありがとうございます。
アリ