Greetings,
I'm developing a voting simulator that will need to display a dynamic # of voting rows (each row is another instance of New.Vote.ascx). I am attempting to build the controls dynamically in the code behind, but I am unable to set the properties of the control. Below is my pertinent code for the both the control and web form.
New.Vote.ascx.cs
//### properties
public string DirectorName = string.Empty;
public int VoteID = 0;
...
Vote.Simulator.aspx.cs
//### load user control
Control Vote = LoadControl("Controls/New.Vote.ascx");
TitlePanel.Controls.Add(Vote);
How can I access these two properties to dynamically set them in a loop?
Thanks in advance for any insight and suggestions.I've figured out the solution...
I was trying to access the properties of a basic control type. It is necessary to cast the control to the proper type (New_Vote, class name for New.Vote.ascx.cs). The proper code is below:
//### load user control
Control c = LoadControl("Controls/New.Vote.ascx");
New_Vote Vote = (New_Vote)c;
//### set control properties
Vote.DirectorName = "Daniel C. Douglass";
Vote.VoteID = 117;
//### add to placeholder
TitlePanel.Controls.Add(Vote);Also, it is even better to cast directly to the New_Vote control, i.e.
//### load user control
New_Vote Vote = (New_Vote)LoadControl("Controls/New.Vote.ascx");
...
I'm developing a voting simulator that will need to display a dynamic # of voting rows (each row is another instance of New.Vote.ascx). I am attempting to build the controls dynamically in the code behind, but I am unable to set the properties of the control. Below is my pertinent code for the both the control and web form.
New.Vote.ascx.cs
//### properties
public string DirectorName = string.Empty;
public int VoteID = 0;
...
Vote.Simulator.aspx.cs
//### load user control
Control Vote = LoadControl("Controls/New.Vote.ascx");
TitlePanel.Controls.Add(Vote);
How can I access these two properties to dynamically set them in a loop?
Thanks in advance for any insight and suggestions.I've figured out the solution...
I was trying to access the properties of a basic control type. It is necessary to cast the control to the proper type (New_Vote, class name for New.Vote.ascx.cs). The proper code is below:
//### load user control
Control c = LoadControl("Controls/New.Vote.ascx");
New_Vote Vote = (New_Vote)c;
//### set control properties
Vote.DirectorName = "Daniel C. Douglass";
Vote.VoteID = 117;
//### add to placeholder
TitlePanel.Controls.Add(Vote);Also, it is even better to cast directly to the New_Vote control, i.e.
//### load user control
New_Vote Vote = (New_Vote)LoadControl("Controls/New.Vote.ascx");
...