Obj. reference not set to an instance of an obj.

magic_e

New Member
Hi I have a webcontrol table in a ASCX, I am trying to turn the table's visibility on and off in a VB file but I got an Error stated as above. There are 4 files involved. Can you please have a look at the code and see anything wrong. <BR><BR>FILE 1 - error.ascx: <BR><asp:Table id="tblErrors" Runat="server"> <BR> <asp:TableRow> <BR> <asp:TableCell> <BR> .................................... <BR> </asp:TableCell> <BR> </asp:TableRow> <BR></asp:Table> <BR><BR>----------------------------------------------------------- <BR><BR>FILE 2 - product.aspx: <BR><%@ Page Language="vb" AutoEventWireup="false" Codebehind="products.aspx.vb" Inherits="project.products"%> <BR><%@ Register TagPrefix="page" TagName="error" Src=http://aspmessageboard.com/archive/index.php/"./ascx/error.ascx" %> <BR><BR><form id="Form1" method="post" runat="server"> <BR> <page:error id="error" runat="server" /> <BR></form> <BR><BR>----------------------------------------------------------- <BR><BR>FILE 3 - product.aspx.vb: <BR>Imports project.CommonFunctions <BR><BR>Public Class products <BR> Inherits System.Web.UI.Page <BR> Protected WithEvents tblErrors As System.Web.UI.WebControls.Table <BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load <BR><BR> pShowError(tblErrors) <BR> End Sub <BR><BR>----------------------------------------------------------- <BR><BR>FILE 4 - CommonFunctions.vb: <BR>Public Class CommonFunctions <BR> Public Shared Sub pShowError(ByVal oTable As System.Web.UI.WebControls.Table) <BR> oTable.Visible = False <BR> End Sub <BR><BR>The ERROR is pointing at "oTable.Visible = False". <BR><BR>ThanksWhy didn't you initialize the Object:<BR><BR>FILE 4 - CommonFunctions.vb: <BR>Public Class CommonFunctions <BR>Public Shared Sub pShowError(ByVal oTable As System.Web.UI.WebControls.Table) <BR>dim oTable as New System.Web.UI.WebControls.Table<BR>or if you "Imports System.Web.UI.WebControls"<BR>you can use:<BR>dim oTable as new table<BR>oTable.Visible = False <BR>End Sub <BR><BR>Try this and it would work<BR>Hi Fadi, is this what U suggest ?<BR><BR>Public Shared Sub pShowError(ByVal oTable As System.Web.UI.WebControls.Table) <BR>dim oTable as New System.Web.UI.WebControls.Table<BR>oTable.Visible = False <BR>End Sub <BR><BR>It said "oTable already declared as a parameter of this method"<BR><BR>Any idea ?Ok <BR>try to do thw following<BR>imports System.Web.UI.WebControls<BR>Public Function pShowError(ByVal as table) as boolean<BR>if oTable.Visible = False <BR>return 1<BR>else<BR>return 0<BR>End Function<BR>I suspect the cause of the problem is that the webcontrol table is in ASCX not in ASPX, therefore the CodeBehind of ASPX cannot find it, am I correct ? If yes how to solve the problem ?<BR><BR>ThanksHi fadi, I have no luck getting it to work. What I have tried to do is to see if I can make it invisible in FILE3:product.aspx.vb, I am not calling the pShowError function in CommonFunctions.vb<BR><BR>Public Class products <BR> Inherits System.Web.UI.Page <BR> Protected WithEvents tblErrors As System.Web.UI.WebControls.Table <BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load <BR><BR> 'pShowError(tblErrors) <BR> tblErrors.visible = False <BR> End Sub <BR><BR>But the error points at tblErrors.visible = False saying "Object reference not set to an instance of an object". So I believe because tblErrors is in ASCX and not in product.aspx, that's why it doesn't work, Right ?Do you still get the errorSame error because the webcontrol is in ASCX and not ASPX which the code behind cannot find it, I still dunno how to access the webcontrol in ASCX
 
Back
Top