Using a webform from a class file

R

Raymond Du

Hi,

I don't know if this is possible, I have a webform named genRept.aspx that
has a datagrid in it. From a VB class file, I would like to access the html
that datagrid in genRept.aspx renders. Here is my code snippets in VB class:

Dim getRept1 as new genRept
Dim strHTML as string
strHTML = genRept.getHTML()


getHTML is a public function in genRept.aspx.vb:
public function getHTML() as string
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Datagrid1.RenderControl(hw)
return tw.ToString()
end function

Err occurs at Datagrid1.RenderControl(hw), error message: Object reference
not set to an instance of an object.

Any suggestions?
TIA
 
D

Derek Harmon

Raymond Du said:
Err occurs at Datagrid1.RenderControl(hw), error message: Object reference
not set to an instance of an object.

Raymond,

Are you certain Datagrid1 is not Nothing at this point? Try,

If ( Datagrid1 Is Nothing ) Then
Return "Datagrid1 Was Nothing!"
Else
Datagrid1.RenderControl( hw )
End If
Return tw.ToString( )

and if that indicates "Datagrid1 Was Nothing!" then make sure
you've assigned the DataGrid to Datagrid1 correctly.

How are you getting the object reference of the DataGrid into
Datagrid1 from the WebForm class?


Derek Harmon
 
R

Raymond Du

Inside the genRept.aspx ,
DataGrid1 is declared as Protected With Events.
Also in Page_load, I get a dataset from SQL server and bind it to DataGrid1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top