How to access values entered in User control in the main page.

V

vineetbatta

Hi Guys,

i have a user control which allows the user to enter Name& Address in text
boxes.

I use the same user control in the main page...

Is there a simple way of accessing the Name & address entered in the text
boxes of the user control in the main page(Page hosting the user control
using Resgister directive.).

Any pointers will be helpful.

regards
Vineet Batta
 
S

Scott Mitchell [MVP]

[Cross-posted from ...framework.aspnet.webcontrols; vineet, please read
http://www.cs.tut.fi/~jkorpela/usenet/xpost.html#why for more info on
good netiquette on crossposting USENET messages....]
i have a user control which allows the user to enter Name& Address in text boxes.

I use the same user control in the main page...

Is there a simple way of accessing the Name & address entered in the
text boxes of the user control in the main page(Page hosting the user
control using Resgister directive.).


Create a couple of Public, read-only properties in the User Control that
return the values of the Web controls. For example, imagine the address
textbox in the UC has an ID of Address. You could, in your UC class, add:

'VB.NET
Public ReadOnly Property AddressValue as String
Get
Return Address.Text
End Get
End Property

// C#
public string AddressValue
{
get {
return Address.Text;
}
}


In your page that contains the UC you'll need to manually add a
reference to the UC and then you can access its property just as you
normally would.

For more information on User Controls, check out my article:

An Extensive Examination of User Controls
http://tinyurl.com/6p2ju

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top