Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > getting web page - control and class to talk to one another is hard...

Reply
Thread Tools

getting web page - control and class to talk to one another is hard...

 
 
Support
Guest
Posts: n/a
 
      03-22-2005
Hello:

I have a aspx web page - let's call it main.aspx
It contains a placeholder: Myplaceholder.

I have a web control, lets call it webcontrol which has a code behind class
called webcontrolclass and a label called mycontrollabel
In the webcontrolclass, I have a private sub called:
Sub writetomycontrollabel(stuff as text)
mycontrollabel.text=stuff
End Sub

The code behind main.aspx
Dim MANAGEGENERAL As Control = LoadControl("webcontrol.ascx") ' needed for
the placeholder
Public MyMANAGEGENERAL As New webcontrolclass


I have a sub which is called by a button located on main.aspx
Sub mainaspx_click(usualstuff ) handles mainaspx.Click
MyPlaceholder.Controls.Add(MANAGEGENERAL)
MyMANAGEGENERAL.writetomycontrollabel("hello")
End sub

I get the error message:
Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
MyMANAGEGENERAL.writetomycontrollabel("hello")

So, I am missing something obvious - but I dont get it.
Help
Thanks
Terry



 
Reply With Quote
 
 
 
 
ashish
Guest
Posts: n/a
 
      03-22-2005
I think you need to load the control using
LoadControl method and then add it to the controls collection. The
problem is that the label control inside your custom control is not
loaded yet..


hth
-ashish


ote:
> Hello:
>
> I have a aspx web page - let's call it main.aspx
> It contains a placeholder: Myplaceholder.
>
> I have a web control, lets call it webcontrol which has a code behind class
> called webcontrolclass and a label called mycontrollabel
> In the webcontrolclass, I have a private sub called:
> Sub writetomycontrollabel(stuff as text)
> mycontrollabel.text=stuff
> End Sub
>
> The code behind main.aspx
> Dim MANAGEGENERAL As Control = LoadControl("webcontrol.ascx") ' needed for
> the placeholder
> Public MyMANAGEGENERAL As New webcontrolclass
>
>
> I have a sub which is called by a button located on main.aspx
> Sub mainaspx_click(usualstuff ) handles mainaspx.Click
> MyPlaceholder.Controls.Add(MANAGEGENERAL)
> MyMANAGEGENERAL.writetomycontrollabel("hello")
> End sub
>
> I get the error message:
> Object reference not set to an instance of an object.
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
> MyMANAGEGENERAL.writetomycontrollabel("hello")
>
> So, I am missing something obvious - but I dont get it.
> Help
> Thanks
> Terry
>
>
>

 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      03-23-2005
Where does

MANAGEGENERAL As Control = LoadControl("webcontrol.ascx")

exist? In Page_Load? Is it executed with every postback and before the
Click event?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 22 Mar 2005 16:15:15 -0500, "Support"
<(E-Mail Removed)> wrote:

>Hello:
>
>I have a aspx web page - let's call it main.aspx
>It contains a placeholder: Myplaceholder.
>
>I have a web control, lets call it webcontrol which has a code behind class
>called webcontrolclass and a label called mycontrollabel
>In the webcontrolclass, I have a private sub called:
>Sub writetomycontrollabel(stuff as text)
> mycontrollabel.text=stuff
>End Sub
>
>The code behind main.aspx
>Dim MANAGEGENERAL As Control = LoadControl("webcontrol.ascx") ' needed for
>the placeholder
>Public MyMANAGEGENERAL As New webcontrolclass
>
>
>I have a sub which is called by a button located on main.aspx
>Sub mainaspx_click(usualstuff ) handles mainaspx.Click
>MyPlaceholder.Controls.Add(MANAGEGENERAL)
> MyMANAGEGENERAL.writetomycontrollabel("hello")
>End sub
>
>I get the error message:
>Object reference not set to an instance of an object.
>Exception Details: System.NullReferenceException: Object reference not set
>to an instance of an object.
> MyMANAGEGENERAL.writetomycontrollabel("hello")
>
>So, I am missing something obvious - but I dont get it.
>Help
>Thanks
>Terry
>
>


 
Reply With Quote
 
Support
Guest
Posts: n/a
 
      03-24-2005
exist before and page Loads ...

Public Class A
Inherits System.Web.UI.Page
Dim MANAGEGENERAL As Control = LoadControl("ManageGeneral.ascx")


Private Sub PAge_Init() Handles MyBAse.Init
End Sub


Private Sub PAge_Load() Handles MyBase.Load
MyPlaceholder.Controls.Add(MANAGEGENERAL)
End Sub

Terry






"Scott Allen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Where does
>
> MANAGEGENERAL As Control = LoadControl("webcontrol.ascx")
>
> exist? In Page_Load? Is it executed with every postback and before the
> Click event?
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Tue, 22 Mar 2005 16:15:15 -0500, "Support"
> <(E-Mail Removed)> wrote:
>
>>Hello:
>>
>>I have a aspx web page - let's call it main.aspx
>>It contains a placeholder: Myplaceholder.
>>
>>I have a web control, lets call it webcontrol which has a code behind
>>class
>>called webcontrolclass and a label called mycontrollabel
>>In the webcontrolclass, I have a private sub called:
>>Sub writetomycontrollabel(stuff as text)
>> mycontrollabel.text=stuff
>>End Sub
>>
>>The code behind main.aspx
>>Dim MANAGEGENERAL As Control = LoadControl("webcontrol.ascx") ' needed for
>>the placeholder
>>Public MyMANAGEGENERAL As New webcontrolclass
>>
>>
>>I have a sub which is called by a button located on main.aspx
>>Sub mainaspx_click(usualstuff ) handles mainaspx.Click
>>MyPlaceholder.Controls.Add(MANAGEGENERAL)
>> MyMANAGEGENERAL.writetomycontrollabel("hello")
>>End sub
>>
>>I get the error message:
>>Object reference not set to an instance of an object.
>>Exception Details: System.NullReferenceException: Object reference not set
>>to an instance of an object.
>> MyMANAGEGENERAL.writetomycontrollabel("hello")
>>
>>So, I am missing something obvious - but I dont get it.
>>Help
>>Thanks
>>Terry
>>
>>

>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      03-24-2005
You might want to turn on two options under Project -> Properties ->
Build: Option Strict and Option Explicit. That might help track down
the source of the error, looking at the code it doesn't seem these
options are on.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 24 Mar 2005 07:40:45 -0500, "Support"
<(E-Mail Removed)> wrote:

>exist before and page Loads ...
>
>Public Class A
>Inherits System.Web.UI.Page
>Dim MANAGEGENERAL As Control = LoadControl("ManageGeneral.ascx")
>
>
>Private Sub PAge_Init() Handles MyBAse.Init
>End Sub
>
>
>Private Sub PAge_Load() Handles MyBase.Load
> MyPlaceholder.Controls.Add(MANAGEGENERAL)
>End Sub
>
>Terry
>
>
>
>
>
>
>"Scott Allen" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> Where does
>>
>> MANAGEGENERAL As Control = LoadControl("webcontrol.ascx")
>>
>> exist? In Page_Load? Is it executed with every postback and before the
>> Click event?
>>
>> --
>> Scott
>> http://www.OdeToCode.com/blogs/scott/
>>
>> On Tue, 22 Mar 2005 16:15:15 -0500, "Support"
>> <(E-Mail Removed)> wrote:
>>
>>>Hello:
>>>
>>>I have a aspx web page - let's call it main.aspx
>>>It contains a placeholder: Myplaceholder.
>>>
>>>I have a web control, lets call it webcontrol which has a code behind
>>>class
>>>called webcontrolclass and a label called mycontrollabel
>>>In the webcontrolclass, I have a private sub called:
>>>Sub writetomycontrollabel(stuff as text)
>>> mycontrollabel.text=stuff
>>>End Sub
>>>
>>>The code behind main.aspx
>>>Dim MANAGEGENERAL As Control = LoadControl("webcontrol.ascx") ' needed for
>>>the placeholder
>>>Public MyMANAGEGENERAL As New webcontrolclass
>>>
>>>
>>>I have a sub which is called by a button located on main.aspx
>>>Sub mainaspx_click(usualstuff ) handles mainaspx.Click
>>>MyPlaceholder.Controls.Add(MANAGEGENERAL)
>>> MyMANAGEGENERAL.writetomycontrollabel("hello")
>>>End sub
>>>
>>>I get the error message:
>>>Object reference not set to an instance of an object.
>>>Exception Details: System.NullReferenceException: Object reference not set
>>>to an instance of an object.
>>> MyMANAGEGENERAL.writetomycontrollabel("hello")
>>>
>>>So, I am missing something obvious - but I dont get it.
>>>Help
>>>Thanks
>>>Terry
>>>
>>>

>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how does one website page class call methods in another page class? Steve Richter ASP .Net 6 05-03-2007 10:34 PM
Skype and Talk Talk Sacred UK VOIP 9 08-01-2006 08:57 PM
getting page and control and class talking to one another is hard.. Support ASP .Net Web Controls 0 03-22-2005 05:44 PM
accessing the web user control's control from a web page and set a value from another web page Reny J Joseph Thuthikattu ASP .Net 1 12-30-2004 12:21 PM
Passing value from one script on one page to another script on another page. Robert Cohen ASP General 3 07-15-2003 01:46 PM



Advertisments