I am currently developing a solution that uses YUI grids. My problem is that my home page is a summary of all my other pages, it includes a summary grid of the grids displayed on other pages, and I dont want to reuse the same code in each page’s code behind. Im trying to centralize it. So what I have done is I have made <asp:Placeholders id="LoadOpenPurchasesGridDataPlaceholder" runat="server"> where I write a JSON string into, on the home page and the Open Purchases Page. However, because I want to share the sub procedure across all pages, I have made it public shared, but it gives an error: cannot refer to an instance member of a class from within a shared method or shared member.
Now if I want to response.write to a page from a different code begind I use HttpContext.Current.Response.Write(). Is there a similar way of accessing the page’s HTML controls from where I am calling it. (I have tried to explain it in detail, sorry for confusion caused.)
My Code:
Shared Sub LoadOpenPurchasesGrid(ByVal Location As String, ByVal Coop As String, ByVal Commodity As String, ByVal Financed As String, ByVal Season As String, ByVal Trader As String, ByVal Department As String, ByVal Database As String)
Try
Dim ReturnString As String = Nothing
If 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)
Else
ReturnString = (LoadOpenPurchasesGridData(Location, Coop, Commodity, Season, Trader, Department, Database))
HttpContext.Current.Response.Write(ReturnString)
End If
HttpContext.Current.Response.Write(ex.message)
End Try
End Sub
I have found the answer to my question. Instead of trying to reference the placeholder directly from the calling method, I rather pass the placeholder as a method parameter, and I send it from the calling method as Me.PlaceholderID.