Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / June 2004

Tip: Looking for answers? Try searching our database.

Labels and usercontrols

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Micke Palm - 29 Jun 2004 11:42 GMT
Hi!

I want to use a parent page and load webusercontrols to this page dynamically. The problem I got is how I can set a label.text in parent page from a usercontrol.

A scenenario is if I have a button into the usercontrol and want to set a text to a label in the parents page. I've set the click_sub to public and the label to friend so I can se it, but when I try to dedicate a text I got this error.
Object reference not set to an instance of an object.

My declaration is ...
Dim test As New myParentClass
test.ChangedBy.Text = "Ett test"

Do anyone have a clue how I can do this. I have also test with a property and I succeed to dedicate the value to the property ,but how can I get it to the label. Maybe I need reload the parent page?

Maybe sessions are a better way to move the data??

/regards, Micke
ranganh - 29 Jun 2004 14:17 GMT
Dear Micke,

In the Usercontrol, set a property

public string lbl_Text
{
     set
    {
                      lbl_Text=value;

    }

}

then when you load the usercontrol in the page, you can also provide the value for the property in the page.

Hope it helps.

> Hi!
>
[quoted text clipped - 12 lines]
>
> /regards, Micke
Micke Palm - 30 Jun 2004 13:04 GMT
I've try a property too and sure I can save data into the property ,but how
can I pick it up. As you know a aspnet is not the same like vbnet cos the
page need to reload and build up all controls from scratch everytime it
loads.
So its no problem to save it into a property the problem is when I need to
get it into the label.

/regards, micke

> Dear Micke,
>
[quoted text clipped - 17 lines]
> >
> > I want to use a parent page and load webusercontrols to this page dynamically. The problem I got is how I can set a label.text in parent page
from a usercontrol.

> > A scenenario is if I have a button into the usercontrol and want to set a text to a label in the parents page. I've set the click_sub to public and
the label to friend so I can se it, but when I try to dedicate a text I got
this error.
> > Object reference not set to an instance of an object.
> >
[quoted text clipped - 3 lines]
> >
> > Do anyone have a clue how I can do this. I have also test with a property and I succeed to dedicate the value to the property ,but how can I
get it to the label. Maybe I need reload the parent page?

> > Maybe sessions are a better way to move the data??
> >
> > /regards, Micke
Jos - 30 Jun 2004 08:20 GMT
>"Micke Palm" <micke@ripoff.nykoping.net> wrote in message
news:OpKaAPcXEHA.3668@TK2MSFTNGP09.phx.gbl...
>Hi!
>
>I want to use a parent page and load webusercontrols to this page dynamically. The problem I got is how I can set a label.text in parent page
from a usercontrol.

>A scenenario is if I have a button into the usercontrol and want to set a text to a label in the parents page. I've set the click_sub to public and
the label to friend so I can se it, but when I try to dedicate a >text I got
this error.
>Object reference not set to an instance of an object.
>
>My declaration is ...
>Dim test As New myParentClass
>test.ChangedBy.Text = "Ett test"

Use:
Dim test As myParentClass = CType(Page,myParentClass)
test.ChangedBy.Text = "Ett test"

By the way, I believe that your problem indicates a flaw in your design.
According to the object oriented philosophy, a user control is
supposed to stand on its own. It shouldn't need to access external
controls, nor should it assume that its parent is of a certain class.

You could consider making the label a part of the user control,
except if you want to add multiple user controls and a single label
to your page. In that case, you could consider adding an event
to the user control, adding an event handler to the page, and
setting the label's text there.

Jos
Micke Palm - 30 Jun 2004 13:08 GMT
CType(Page,myParentClass)
Did the trick...thanks!

I understand what you mean with "a webuser control should stand alone" and I
agree ,but in this case I really need it cos I building a Wizard and I don't
want all code in the same page. That's the reason.

/Thanks for the help, micke

> >"Micke Palm" <micke@ripoff.nykoping.net> wrote in message
> news:OpKaAPcXEHA.3668@TK2MSFTNGP09.phx.gbl...
[quoted text clipped - 30 lines]
>
> Jos

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.