0

私は現在、YUIグリッドを使用するソリューションを開発しています。私の問題は、私のホームページが他のすべてのページの要約であり、他のページに表示されるグリッドの要約グリッドが含まれていることです。各ページのコードビハインドで同じコードを再利用したくありません。私はそれを一元化しようとしています。つまり<asp:Placeholders id="LoadOpenPurchasesGridDataPlaceholder" runat="server">、ホームページとOpen Purchasesページで、JSON文字列を書き込む場所を作成しました。ただし、サブプロシージャをすべてのページで共有したいので、パブリック共有にしましたが、エラーが発生します。共有メソッドまたは共有メンバー内からクラスのインスタンスメンバーを参照できません。

ここで、開始した別のコードからページへのresponse.writeを実行する場合は、HttpContext.Current.Response.Write()を使用します。私が呼び出している場所からページのHTMLコントロールにアクセスする同様の方法はありますか?(ご迷惑をおかけして申し訳ございませんが、詳しく説明させていただきました。)

私のコード:

Shared Sub LoadOpenPurchasesGrid(ByVal Location As String、ByVal Coop As String、ByVal Commodity As String、ByVal Financeed As String、ByVal Season As String、ByVal Trader As String、ByVal Department As String、ByVal Database As String)
    試す
        Dim ReturnString As String = Nothing
        Location = "0" And Coop = "0" And Commodity = "0" And Season = "0" And Trader = "0" Then
             ReturnString =(LoadOpenPurchasesGridData( ""、 ""、 ""、 ""、 ""、Department、Database))
             Dim LoadGridDataContainer As New HtmlGenericControl( "input")
             LoadGridDataContainer.ID = "hdnOpenPurchasesGridData"
             LoadGridDataContainer.Attributes.Add( "type"、 "hidden")
             LoadGridDataContainer.Attributes.Add( "value"、ReturnString)
             LoadOpenPurchasesGridDataPlaceholder.Controls.Add(LoadGridDataContainer)
        そうしないと
             ReturnString =(LoadOpenPurchasesGridData(Location、Coop、Commodity、Season、Trader、Department、Database))
             HttpContext.Current.Response.Write(ReturnString)
        終了する場合
        HttpContext.Current.Response.Write(ex.message)
    終了試行
サブ終了

4

1 に答える 1

0

私は私の質問に対する答えを見つけました。呼び出し元のメソッドから直接プレースホルダーを参照するのではなく、メソッドパラメーターとしてプレースホルダーを渡し、呼び出し元のメソッドからMe.PlaceholderIDとして送信します。

' Public Shared Sub LoadOpenPurchasesGridData(ByRef Placeholder As Object, ByVal Location As String, ByVal Coop As String, ByVal Commodity As String, ByVal Season As String, ByVal Trader As String, ByVal SearchCriteria As String, ByVal Department As String, ByVal Database As String, ByVal InitialLoad As Boolean)
        Dim SqlConnection As New SqlConnection
        Dim SqlCommand As New SqlCommand
        Dim SqlParameter As New List(Of SqlParameter)
        Dim SqlReader As SqlDataReader = Nothing
        Dim ReturnString = "["
        Dim Counter As Integer = 1
        Try
            SqlConnection = CreateDatabaseConnection(ConnectionString)
            AddSqlParameterToCollection(SqlParameter, "@Location", Location)
            AddSqlParameterToCollection(SqlParameter, "@Coop", Coop)
            AddSqlParameterToCollection(SqlParameter, "@Commodity", Commodity)
            AddSqlParameterToCollection(SqlParameter, "@Season", Season)
            AddSqlParameterToCollection(SqlParameter, "@Trader", Trader)
            AddSqlParameterToCollection(SqlParameter, "@Search", SearchCriteria)
            AddSqlParameterToCollection(SqlParameter, "@Database", Database)
            SqlCommand = CreateSqlCommand("[proc_Dynamic_GetPOC]", SqlConnection, SqlParameter)
            SqlReader = SqlCommand.ExecuteReader()
            If SqlReader.HasRows Then
                Do While SqlReader.Read And Counter < 200
                    If Counter <> 1 Then
                        ReturnString += ","
                    End If
                    ReturnString += "{""PrimCont"":""" & SqlReader("PrimCont") & ""","
                    ReturnString += """PSCM_COOP_ID"":""" & SqlReader("PSCM_COOP_ID") & ""","
                    ReturnString += """POCNumber"":""" & SqlReader("POCNumber") & ""","
                    ReturnString += """VENDORID"":""" & SqlReader("VENDORID") & ""","
                    ReturnString += """VendorContract"":""" & SqlReader("VendorContract") & ""","
                    ReturnString += """ITMCLSDC"":""" & SqlReader("ITMCLSDC") & ""","
                    ReturnString += """CommodityGrade"":""" & SqlReader("CommodityGrade") & ""","
                    ReturnString += """ContractQty"":""" & SqlReader("ContractQty") & ""","
                    ReturnString += """LIQty"":""" & SqlReader("LIQty") & ""","
                    ReturnString += """TonsNotFinalized"":""" & SqlReader("TonsNotFinalized") & ""","
                    ReturnString += """POC_DEL_QTY"":""" & SqlReader("POC_DEL_QTY") & ""","
                    ReturnString += """OpenQty"":""" & SqlReader("OpenQty") & ""","
                    ReturnString += """ContractPrice"":""" & SqlReader("ContractPrice") & ""","
                    ReturnString += """PurchaseBasis"":""" & SqlReader("PurchaseBasis") & ""","
                    ReturnString += """Safex Month"":""" & SqlReader("Safex Month") & ""","
                    ReturnString += """SpreadToSafexMonth"":""" & SqlReader("SpreadToSafexMonth") & ""","
                    ReturnString += """LOCNDSCR"":""" & SqlReader("LOCNDSCR") & ""","
                    ReturnString += """Area"":""" & SqlReader("Area") & ""","
                    ReturnString += """VesselName"":""" & SqlReader("VesselName") & ""","
                    ReturnString += """DeliveryMonth"":""" & SqlReader("DeliveryMonth") & ""","
                    ReturnString += """SignedContract"":""" & SqlReader("SignedContract") & """}"
                    Counter += 1
                Loop
            End If
            ReturnString += "]"
            Counter = 0
            If InitialLoad = True Then
                Dim LoadGridDataContainer As New HtmlGenericControl("input")
                LoadGridDataContainer.ID = "hdnOpenPurchasesGridData"
                LoadGridDataContainer.Attributes.Add("type", "hidden")
                LoadGridDataContainer.Attributes.Add("value", ReturnString)
                Placeholder.Controls.Add(LoadGridDataContainer)
            Else
                HttpContext.Current.Response.Write(ReturnString)
            End If
        Catch ex As Exception
            HttpContext.Current.Response.Write("<span class=""error_message_span"">ERROR - An error occurred loading the open puchases grid. Please contact the system administrators for assistance.</span>" & ex.Message)
        Finally
            If Not IsNothing(SqlReader) Then
                SqlReader.Close()
                SqlReader = Nothing
            End If
            If Not IsNothing(SqlCommand) Then
                SqlCommand.Dispose()
                SqlCommand = Nothing
            End If
            If Not IsNothing(SqlConnection) Then
                SqlConnection.Close()
                SqlConnection.Dispose()
                SqlConnection = Nothing
            End If
        End Try
    End Sub'
于 2012-04-26T07:12:26.167 に答える