0

我目前正在开发一个使用 YUI 网格的解决方案。我的问题是我的主页是我所有其他页面的摘要,它包括显示在其他页面上的网格的摘要网格,我不想在每个页面的代码后面重用相同的代码。我试图集中它。所以我所做的是我<asp:Placeholders id="LoadOpenPurchasesGridDataPlaceholder" runat="server">在主页和 Open Purchases 页面上写了一个 JSON 字符串。但是,因为我想在所有页面之间共享子过程,所以我将其设为公共共享,但它给出了一个错误:无法从共享方法或共享成员中引用类的实例成员。

现在,如果我想从不同的代码开始响应.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 = 无
        如果 Location = "0" And Coop = "0" And Commodity = "0" And Season = "0" And Trader = "0" 那么
             ReturnString = (LoadOpenPurchasesGridData("", "", "", "", "", 部门, 数据库))
             将 LoadGridDataContainer 调暗为新 HtmlGenericControl("input")
             LoadGridDataContainer.ID = "hdnOpenPurchasesGridData"
             LoadGridDataContainer.Attributes.Add("类型", "隐藏")
             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(例如消息)
    结束尝试
结束子

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 回答