• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

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!!!
0
taz8020
Asked:
taz8020
  • 3
  • 2
2 Solutions
 
CodeCruiserCommented:
0
 
Ramkisan JagtapLead DeveloperCommented:
u can use webcontrol.findcontrol("controlid") method to find ur control. Then access its text.
0
 
taz8020Author Commented:
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.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CodeCruiserCommented:
Use the following

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

Remember to add error handling
0
 
taz8020Author Commented:
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
0
 
CodeCruiserCommented:
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now