dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Access parent page's control from a user control

  1. #1
    Join Date
    Sep 2004
    Posts
    8

    Access parent page's control from a user control

    I have a .ascx user control that contains a button. I place this user control on a .aspx web page. The web page contains a textbox. When I click on the button in the user control I want the data in the textbox (in the web page) to be saved to the database. I want to write this code in the click event of the user control's button. Is there any way I can access the parent web page's controls from the user control?

  2. #2
    Join Date
    Dec 2004
    Location
    Saint Petersburg, Florida
    Posts
    32
    Yes, there is a way.

    Dim obj As Object
    Dim obj1 As Object
    Dim strText As String

    For Each obj In Me.Page.Controls
    strText = obj.UniqueId
    If strName = "Form1" Then
    obj1 = obj.FindControl("txtData")
    If Not obj1 Is Nothing Then
    strName = obj1.text()
    Exit For
    End If
    End If
    Next


    Where "Form1" is the name of the form of your .aspx page, and txtData is your textbox on that page.
    You write this code in the event handler of the button on your user control.

    Good Luck!

    Happy New Year!

  3. #3
    Join Date
    Jul 2004
    Posts
    300
    Every control has a parent property that you can use to access the parent.

  4. #4
    Join Date
    Dec 2004
    Location
    Saint Petersburg, Florida
    Posts
    32
    You are right!

  5. #5
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    Originally posted by mattyblah
    Every control has a parent property that you can use to access the parent.
    And this relates to the fact that asp.net is fully object oriented and inheritance is one property of object oriented programming.

  6. #6
    Join Date
    Sep 2004
    Posts
    8
    Thanks all of you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles