code_junkie

How can I pass a data string to a programmatically loaded custom user control in C#

Nov 12th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. UserControl myUC = (UserControl).Load("~/customUserControl.ascx");
  2.  
  3. Bob b = (Bob).Load("~/customUserControl.ascx");
  4.  
  5. class Bob : UserControl{
  6. public string User { get; set;}
  7. }
  8.  
  9. b.User = theuser;
  10.  
  11. MyUserControl myUCTyped = (MyUserControl)myUC;
  12. myUCTyped.ThePublicProperty = "some value";
  13.  
  14. MyUserControl myUC = (UserControl).Load("~/customUserControl.ascx") as MyUserControl;
  15. string result = myUC.user;
  16.  
  17. public partial class todo : System.Web.UI.UserControl
  18. {
  19. private string mysecondteststring;
  20. public string setValue
  21. {
  22. get
  23. {
  24. return mysecondteststring;
  25. }
  26. set
  27. {
  28. mysecondteststring = value;
  29. }
  30. }
  31. protected void Page_Load(object sender, EventArgs e)
  32. {
  33. // my code
  34. }
  35. }
Add Comment
Please, Sign In to add comment