Link to home
Start Free TrialLog in
Avatar of taz8020
taz8020Flag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.NET How you use access a vaule used on the main form, from within a user control

Hi I have a user control within a web page. The page is filled with data using the sqldatasource.

On the main page I am using Text='<%# Eval("ShortDescription") %>'
And from within the usercontrol on the same page I want to be able to get the ShortDescription on the parent page.

I know i could probable do this using varibles but there must be an easy way!!!
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of taz8020

ASKER

Thanks both I can see how both these would work, before i posted this i tried puting the value in a session varible.

My problem is my label Called 'LabelDesc' is in a table Called 'ProductTable' which is in a form called 'formview1'

How do i access it? and which out of the 3 options is best?

Session("ProductDescpription")  =  LabelDesc.text       does not work coz in a form
Session("ProductDescpription")  =  formview1.LabelDesc.text      does not work
Dim MyLabel as Label = CType(webcontrol.findcontrol("LabelDesc"),Label) does not work

Please help.

Use the following

Dim MyLabel As Label = FormView1.Findcontrol("ProductTable").FindControl("LabelDesc")

Remember to add error handling
Avatar of taz8020

ASKER

CodeCruiser, Once again thank you. Just to finish I now see how both work. Which would you say is best

using:
Public ReadOnly Property ProductDescpription() As String
Get
 Return _ProductDescpription
End Get
End Property

Or

Dim MyLabel As Label = FormView1.FindControl("LabelDesc")
Session("ProductDescpription") = MyLabel.Text
You are welcome.

Both approaches are fine. With the second approach, you would need to add error handling to make sure that a label is found before you try to access it.