Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing data from a user control

Status
Not open for further replies.

aolb

Programmer
Apr 16, 2002
180
GB
I am new to asp.net.

I have created a user control that has a text tox in it and I have put it onto a web form. (I am doing this with a reference book in one hand!)

When I run it I get the user control loaded onto my form ok, The buttons do what they are suposed to do and the text box gets populated.

The problem is that I can't pass the value in the text box in the user control to a text box in the web form.

I have created a public property "pViewMode" in the user control and call that from the web form.

The code compiles and executes but falls over when it tries to get the public property "pViewMode" (TextBox1.Text = ViewMode.pViewMode.ToString())

The code to set a value to pViewMode does not get executed and so the value of ViewMode.pViewMode.ToString() is nothing.

Any idea would be appricated

 
1. Are you using Page.LoadControl() to create the user control?
2. When are you trying to access the property?
 
1. Are you using Page.LoadControl() to create the user control?

Nope.


2. When are you trying to access the property?

I have a combobox on my parent form. On the change event of that combobox I want to populate the valve of a text field in the user control into a text field on the parent form.

From my understanding of user controls, I should be able to do this by:

1. using the command TextBox1.Text = ViewMode.pViewMode.ToString() on the Parent form, which then calls

2. public property "pViewMode" which will obtain the value I want from the text box on the user control

3. And assign that value to TextBox1

What am I missing???
 
You need to use Page.LoadControl() to instantiate dynamic user controls because there's some extra processing involved with associating the code class with the markup. All of the user control's controls will be null/nothing if you try to instantiate the control directly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top