access one user control from other on same page
-
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
-
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
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
-
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
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. -
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
can u plz show with some code or e.g
-
can u plz show with some code or e.g
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
-
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
ok.thx