473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Using a webform from a class file

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
Nov 19 '05 #1
2 858
"Raymond Du" <rd**@yahoo.com> wrote in message news:OC***************@TK2MSFTNGP11.phx.gbl...
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
Nov 19 '05 #2
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.

"Derek Harmon" <lo*******@msn.com> wrote in message
news:e6**************@TK2MSFTNGP11.phx.gbl...
"Raymond Du" <rd**@yahoo.com> wrote in message

news:OC***************@TK2MSFTNGP11.phx.gbl...
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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bita-kookoo | last post by:
I am having a problem with inheritance for my web solution. Here are the steps I took for a project within C#: -I first created a new class, descended from System.Web.UI.Page. For this...
2
by: Lauchlan M | last post by:
Hi. Following the example at http://www.codeproject.com/useritems/ooaspnet.asp?print=true, I have a datagrid descendant class that shows a JavaScript confirm dialog before deleting a row from...
2
by: John A Grandy | last post by:
for the code-behind a WebForm, it's easy to use ASP.NET session state -- just refer to the built-in Session object ... but how to write code elsewhere that utilizes this same object ? within a...
1
by: timmso | last post by:
If I create a webform in notepad (save it with an .aspx extension), I can see the VB.Net code along with the ASP.Net code in one file. If I create an Asp.Net web application and add a web form...
1
by: Christian (France) | last post by:
I created a class to log application event in my webform. This "Logs" class contains only one static method : static void WriteLog(string mess) { StreamWriter log log =...
6
by: Skeptical | last post by:
Hello, I am trying to embed html output into my webform but could not figure out how to so far. The form will execute a Perl script with some parameters, and script will output some html...
8
by: vinesh | last post by:
I have sample Asp.Net Web Application project. Let me know how to keep the files related to this project (like the webform.aspx, WebForm1.aspx.vb, WebForm1.aspx.resx) in a separate folder within a...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
3
by: Dean Slindee | last post by:
Would like to call the TabShow function on WebForm InOutHost from another WebForm in same project, but cannot figure out how to get a reference. Can this be done? In this statement: Call...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.