I'm still lost how to have a control send a value back to a page.

U

UJ

I've got a user control with a drop down list of stuff. I want to have it so
that when the user changes the value in the list, it will show up in a label
on the main portion of the page. I can't figure out how to do it correctly.
I've tried setting a session variable when the drop down list changes but
the setting of the session variables seems to happen after the page_load
event has already happened.

Can anybody please help me?

All I want is the user object to change selected values and be able to
change a label on the main page to reflect that change......

TIA - Jeffrey.
 
G

Guest

This is how I would go about this:

(1) Create a public property on your user control ie: private string
selectedText = ""; public string SelectedText{ get{return this.selectedText;
} }
(2) In the selected index changed event method on the drop down set that
property as desired;

(3) Wire up a PreRender event on this host page which does this.myLabel.Text
= this.myControl.SelectedText;

That should be all you need, hope that helps.
 
J

jhcorey

I've seen other techniques that are more 'correct' as far as
object-oriented principle are concerned, but I've used something like
this:

In my control I define a variable as the same type as the page (assume
it's MainPage.aspx):
Protected myParentPage As MainPage

Then in the code I can access the public properties and functions of
MainPage:

myParentPage.SetLabel(myText)
 
U

UJ

I tried doing it in preRender - but the object hasn't been defined yet.....

Any more suggestions?
 
U

UJ

Let me clarify - in the debugger, the value in prerender of my user control
is still set to nothing meaning the variable hasn't been defined yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top