66chawger
asked on
Access UserControl set() method from code behind
I have form1.aspx and code behind for this form (form1.aspx.cs). I have a UserControl (UserControl1.cs) that is built in a package dll that is included in the project. The DLL has been added as a reference.
What I am trying to do is access UserControl1's Set() method from within my code behind (form1.aspx.cs).
Here is an example of the set method in UserControl1.cs. FYI, I am not using the get() method at this time.
public string psField1
{
get { return __Field1; }
set { _Field1 = value; }
}
So, in form1's code behind, I assume I will have to instantiate UserControl1.cs first.
PackageControl.UserControl 2.......
now I need the rest to access the set() method in UserControl1.cs to set
What I am trying to do is access UserControl1's Set() method from within my code behind (form1.aspx.cs).
Here is an example of the set method in UserControl1.cs. FYI, I am not using the get() method at this time.
public string psField1
{
get { return __Field1; }
set { _Field1 = value; }
}
So, in form1's code behind, I assume I will have to instantiate UserControl1.cs first.
PackageControl.UserControl
now I need the rest to access the set() method in UserControl1.cs to set
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
renjurdevan, thanks for the example. I do have one more question.
My UserControl2 public stringw/ set method is below. Now, looking at your example for .MyMethod(); as you indicated previously, how am I actually coding to set serverName? I know this sounds lame, please bare with me!
public string psServerName
{
get { return serverName; }
set { serverName = value; }
}
My UserControl2 public stringw/ set method is below. Now, looking at your example for .MyMethod(); as you indicated previously, how am I actually coding to set serverName? I know this sounds lame, please bare with me!
public string psServerName
{
get { return serverName; }
set { serverName = value; }
}
psServerName is a property of the Control so all you need do is call
//Setting the property
yourControl.psServerName = "ServerName";
//Getting the property
string serverName = yourControl.psServerName;
//Setting the property
yourControl.psServerName = "ServerName";
//Getting the property
string serverName = yourControl.psServerName;
where yourControl is the refrence to the obj instatiated in the other posters answer
ASKER
Thanks alot! I feel really lame, this seems to obvious..LOL.
McExp, I accepted the other posters response, but I want to acknowledge you also. Can you only accept one response?
McExp, I accepted the other posters response, but I want to acknowledge you also. Can you only accept one response?
You can do somthing about awarding points for an assist, I've never asked a question so can't tell you how this is done.
ASKER
Ok, receiving a build error:
Cannot convert type 'System.Web.UI.Control' to 'PackageControl.UserContro l2' on the following:
obj = (UserControl2) LoadControl("UserControl2. cs")
I think this has something to do with UserControl2 being defined as a public class using System.Windows.Forms.UserC ontrol
Cannot convert type 'System.Web.UI.Control' to 'PackageControl.UserContro
obj = (UserControl2) LoadControl("UserControl2.
I think this has something to do with UserControl2 being defined as a public class using System.Windows.Forms.UserC
If it's on a page you should already have a refernce to the control so you can call UserControl1.psField where UserControl1 is the ID of the control
If it has not been added to a page then yes you would have to create an instance of the control but accessing the property will be the same as above