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 one user control from other on same page

access one user control from other on same page

Scheduled Pinned Locked Moved ASP.NET
questionhelp
6 Posts 3 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.
  • M Offline
    M Offline
    max_dev2006 yahoo com
    wrote on last edited by
    #1

    hi, I have two usercontrol on same page. 1.ascx and 2.ascx on abc.aspx . Now I need to access dropdown on 1.ascx frm 2.ascx . Plz help me how can i do this? I have tried Page.findcontrol but as a user control inherits usercontrol class and not page class . its not giving reference to proeprty Page.Findcontrol. I can do page.findcontrol on aspx page but I need to do it on ascx only. plz helpp regards, max

    C M 2 Replies Last reply
    0
    • M max_dev2006 yahoo com

      hi, I have two usercontrol on same page. 1.ascx and 2.ascx on abc.aspx . Now I need to access dropdown on 1.ascx frm 2.ascx . Plz help me how can i do this? I have tried Page.findcontrol but as a user control inherits usercontrol class and not page class . its not giving reference to proeprty Page.Findcontrol. I can do page.findcontrol on aspx page but I need to do it on ascx only. plz helpp regards, max

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I'd tend to use delegates to allow events in one control to communicate something to the main page, which can then pass the info on to the other control as appropriate.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      M 1 Reply Last reply
      0
      • M max_dev2006 yahoo com

        hi, I have two usercontrol on same page. 1.ascx and 2.ascx on abc.aspx . Now I need to access dropdown on 1.ascx frm 2.ascx . Plz help me how can i do this? I have tried Page.findcontrol but as a user control inherits usercontrol class and not page class . its not giving reference to proeprty Page.Findcontrol. I can do page.findcontrol on aspx page but I need to do it on ascx only. plz helpp regards, max

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        The FindControl method looks for a control in the scope of the current naming container, here is the Page instance, so you need to get reference to the naming container of the dropdownlist, maybe the 1.ascx user control, then you can call the FindControl method. However, like Christian said you'd better use the event/delegate to communicate the user controls, it's much more flexible.

        1 Reply Last reply
        0
        • C Christian Graus

          I'd tend to use delegates to allow events in one control to communicate something to the main page, which can then pass the info on to the other control as appropriate.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          M Offline
          M Offline
          max_dev2006 yahoo com
          wrote on last edited by
          #4

          can u plz show with some code or e.g

          C 1 Reply Last reply
          0
          • M max_dev2006 yahoo com

            can u plz show with some code or e.g

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Do you not know how to use delegates ? Google has lots of examples... public class UserControl1 { public delegate void PassAString(string s); public PassAString OnPass; public void SomeEvent(object sender, EventArgs ea) { if (PassAString != null) PassAString("this is the value"); } } public class Form1 { protected UserControl1 u1; protected UserControl2 u2; private void GetAString(string s) { u2.TheString = s; } private void OnLoad(//etc { u1.OnPass += new UserControl1.PassAString(this.GetAString); } } So, the main form hooks up the event, and when it fires, it takes the value it's passed ( whatever that is ) and sends it to the other control.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            M 1 Reply Last reply
            0
            • C Christian Graus

              Do you not know how to use delegates ? Google has lots of examples... public class UserControl1 { public delegate void PassAString(string s); public PassAString OnPass; public void SomeEvent(object sender, EventArgs ea) { if (PassAString != null) PassAString("this is the value"); } } public class Form1 { protected UserControl1 u1; protected UserControl2 u2; private void GetAString(string s) { u2.TheString = s; } private void OnLoad(//etc { u1.OnPass += new UserControl1.PassAString(this.GetAString); } } So, the main form hooks up the event, and when it fires, it takes the value it's passed ( whatever that is ) and sends it to the other control.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              M Offline
              M Offline
              max_dev2006 yahoo com
              wrote on last edited by
              #6

              ok.thx

              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