How to pass a string of data to a programmatically loaded custom control in C #
Call your user control "Bob"
If you inherit UserControl in Bob, then I'm sure it's safe:
Bob b = (Bob).Load("~/customUserControl.ascx");
For the user part, I can't follow what you want to do, it is "user" in the class, you created a custom control "Bob" and you want to set a property in the custom control "Bob" or is it the other way around?
For the former, you have to create a property in your usercontrol.
class Bob : UserControl{
public string User { get; set;}
}
and then install it when after instantiating "Bob".
b.User = theuser;
source to share
Thank. My code looks the same as above:
public partial class todo : System.Web.UI.UserControl
{
private string mysecondteststring;
public string setValue
{
get
{
return mysecondteststring;
}
set
{
mysecondteststring = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
// my code
}
}
But I am unable to instantiate the poll in my web service code. Did I forget something?
-> Forgot to add Reference
to the .aspx page where the custom control is loaded dynamically. It now works with regular .aspx Pages. Sample code can be found here
Does anyone of you know how custom controls can be added to web services since the reference attribute is not available there?
source to share