Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > controls getting values from another control---within a control

Reply
Thread Tools

controls getting values from another control---within a control

 
 
DC Gringo
Guest
Posts: n/a
 
      09-15-2004
I am a bit twisted and need some straightening out. I have a webform with 3
controls on it: a mainHeader, a sectionHeader with a label control contained
in the mainHeader, and a topHeadline.

In the topHeadline, I am retrieving a value with a stored procedure. I need
to set that value to a label control within the sectionHeader like this:

mainHeader1.sectionHeader1.sectionHeaderLabel.Text = myVariable

In topHeadlines, I have:

Public countryName As String
Protected mainHeader1 As mainHeader
Protected sectionHeader1 As sectionHeader

(In Page Load): mainHeader1.sectionHeader1.sectionHeaderLabel.Text =
myVariable

The error I get is: "Object reference not set to an instance of an object."

What am I doing wrong?

_____
DC G



--
_____
DC G


 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      09-16-2004
Hi, DC Gringo,

My preferred approach is to create an interface and then implement it in all
page classes that have the mentioned controls in them. In your case the
interface will have one method in it:

Public Interface IPageWithHeaders
Public Sub SetLabelText(ByVal text As String)
End Interface

Then in the implementation in each page class you will access the control in
sectionHeader (the recommended way is to expose the sectionHeaderLabel.Text
as public string property of the sectionHeader class) and set its value to
the value of the passed parameter.

In topHeadline you will cast the Page property to your interface and call
the method:

DirectCast(Me.Page, IPageWithHeaders).SetLabelText(someValue)

Hope this helps
Martin
"DC Gringo" <> wrote in message
news:...
> I am a bit twisted and need some straightening out. I have a webform with

3
> controls on it: a mainHeader, a sectionHeader with a label control

contained
> in the mainHeader, and a topHeadline.
>
> In the topHeadline, I am retrieving a value with a stored procedure. I

need
> to set that value to a label control within the sectionHeader like this:
>
> mainHeader1.sectionHeader1.sectionHeaderLabel.Text = myVariable
>
> In topHeadlines, I have:
>
> Public countryName As String
> Protected mainHeader1 As mainHeader
> Protected sectionHeader1 As sectionHeader
>
> (In Page Load): mainHeader1.sectionHeader1.sectionHeaderLabel.Text =
> myVariable
>
> The error I get is: "Object reference not set to an instance of an

object."
>
> What am I doing wrong?
>
> _____
> DC G
>
>
>
> --
> _____
> DC G
>
>



 
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
Getting values from another control in a datalist Regan ASP .Net 2 03-12-2008 01:54 AM
Get controls values upon auto-postback of another control inside DataGrid postings@alexshirley.com ASP .Net Datagrid Control 0 04-29-2005 02:08 PM
Getting values from control to control to control Rock ASP .Net Building Controls 0 10-19-2004 10:54 PM
controls getting values from another control---within a control DC Gringo ASP .Net Web Controls 1 09-16-2004 07:59 AM
controls getting values from another control---within a control DC Gringo ASP .Net 0 09-15-2004 04:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57