Results 1 to 2 of 2

Thread: Acessing an ArrayList on the masterpage from a UserControl

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Acessing an ArrayList on the masterpage from a UserControl

    Can this be done?

    I can access controls such as textboxes, labels etc but i can't seem to access my ArrayList. I have:

    Code:
    ArrayList MyArrayList= (ArrayList)this.Page.FindControl("ListNameArray");
    I also have int and string values that i need to pass back and forth from the masterpage and usercontrol, how can this be done?


    Any help grately appreciated.

  2. #2
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: Acessing an ArrayList on the masterpage from a UserControl

    Which UserControl? do u mean Content Page of the master page or something else?

    If UserControl is Content Page then,
    ---------------------------------
    First thing is ArrayList is not an Control. So, u can't access it using Findcontrol method.

    However, It's very easy to get arrayList value. Just define one public variable arrayList in ChildControl (Content Page).

    Suppose u have one Master Page 'Main.master' and and a Content Page 'WebForm1.aspx' the following code can give u some idea abt it.

    Code:
    Public Partial Class WebForm1
        Inherits System.Web.UI.Page
        Public arrList As ArrayList
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          
        End Sub
    
    End Class
    Code:
    Public Partial Class Main
        Inherits System.Web.UI.MasterPage
    
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub btnCheckArrayList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckArrayList.Click
    
            If DirectCast(Me.Parent, WebForm1) IsNot Nothing Then
                Dim objClassOfWebForm1 As WebForm1 = DirectCast(Me.Parent, WebForm1)
                objClassOfWebForm1.arrList = New ArrayList()
                Response.Write("created")
            End If
        End Sub
    End Class
    I am using .NET 2010 with Windows 7

Posting Permissions

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



Click Here to Expand Forum to Full Width