1

ScriptManager.ScriptResourceMappingPathDebugPath属性を利用するために)使用して参照したいクライアント側スクリプトを使用してカスタムコントロールを構築しています。

カスタムコントロールを他のプロジェクトに簡単に移植したい-つまり、コードビハインドファイルをドラッグアンドドロップしたい(そして最終的にはコントロールを別のDLLにしたいが、今のところドラッグアンドドロップで十分だ)。したがって、(1)クライアントスクリプトを埋め込みリソースとして使用したり、(2)で参照したり、(3)でを使用したりすることは避けたいWebResourceAssemblyInfo思い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

質問が理にかなっていることを願っています。時間を割いて読んでいただきありがとうございます。

アリ

4

1 に答える 1

2

自分でこれに答えると、のアセンブリとコンストラクターと混同されていましたScriptReference。(マップされたScriptReference)名前のが必要だったので、空白のコンストラクターを使用してからを設定しNameました。その後、アセンブリ情報を削除できます。

以下を調整すると、問題が解決されました。

Public Sub New()

    ' Add the resource mapping
    ScriptManager.ScriptResourceMapping.AddDefinition("MyControlScript", New ScriptResourceDefinition With {
        .Path = "Path.To.MyControlScript.minimised.js",
        .DebugPath = "Path.To.MyControlScript.original.js"
    })

    ' Set the script reference
    _scriptReference = New ScriptReference() With {.Name="MyControlScript"}

End Sub
于 2012-12-17T11:32:43.270 に答える