Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Access User Control property from Main page

Access User Control property from Main page

Scheduled Pinned Locked Moved ASP.NET
questiondesignsysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peacefulmember
    wrote on last edited by
    #1

    Hi, Got a user control in my master page. I want to access the prperty of user control from the main page. How can I do that? Thanks
    <%@ Register TagPrefix="ucl" TagName="myCntrl" Src="~/UCL.ascx" %> <ucl:myCntrl runat="server" /> Partial Class UCL Inherits System.Web.UI.UserControl Priavte x as String = "" Public Property ConCatStr() As String Get Return x & "Color" End Get Set(ByVal value As String) Dim x As String = value End Set End Property End Class Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Want to refer controls's ConCatStr property on PostBack End Sub

    T 1 Reply Last reply
    0
    • P peacefulmember

      Hi, Got a user control in my master page. I want to access the prperty of user control from the main page. How can I do that? Thanks
      <%@ Register TagPrefix="ucl" TagName="myCntrl" Src="~/UCL.ascx" %> <ucl:myCntrl runat="server" /> Partial Class UCL Inherits System.Web.UI.UserControl Priavte x as String = "" Public Property ConCatStr() As String Get Return x & "Color" End Get Set(ByVal value As String) Dim x As String = value End Set End Property End Class Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Want to refer controls's ConCatStr property on PostBack End Sub

      T Offline
      T Offline
      Talal Sultan
      wrote on last edited by
      #2

      Hi, I'll put that down in C# as I'm not really familiar with VB.NET exact syntax, sorry. In the main page load method:

      UserControl myMasterControl = (UserControl)this.Master.FindControl("myCntrl");

      string myProperty = myMasterControl.ConCatStr;

      -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

      P 1 Reply Last reply
      0
      • T Talal Sultan

        Hi, I'll put that down in C# as I'm not really familiar with VB.NET exact syntax, sorry. In the main page load method:

        UserControl myMasterControl = (UserControl)this.Master.FindControl("myCntrl");

        string myProperty = myMasterControl.ConCatStr;

        -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

        P Offline
        P Offline
        peacefulmember
        wrote on last edited by
        #3

        I tried doing what you mentioned. Did not work! Do I need to assign an ID to the user control? Without that I am not able to findControl on the page.<ucl:myCntrl runat="server" id="uclCntrl" /> On page load: Dim ucl As System.Web.UI.UserControl ucl = Me.Master.FindControl("uclCntl") Response.Write("Found User control " & (Not ucl Is Nothing) & " !") ' I get True for this ucl.Test() 'ERROR: Test is not a member of System.Web.UI.UserControl
        What is wrong here?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups