ASP.NET User Control Pass String Variable From Parent Codebehind?

I know how to pass a hard-code variable on the Parent aspx like this:

   <myControls:SignUpForm ID="SignUpForm" SubscriptionID = "1" runat="server" />

[SignUpForm.ascx.cs]
public partial class UserControls_SignUpForm : System.Web.UI.UserControl
{
        public string subscriptionID {get; set;}

        protected void Page_Load(object sender, EventArgs e)
        {
            string id = subscriptionID; //Works with hard-coded var
        }
}

Open in new window


However, I really need dynamic variables from a Repeater control on the same Parent page:
 
 Q1. Can I use the Repeater Eval variable directly?
 Q2. Can I use the Repeater Eval in the Parent codebehind?

[Repeater]
<asp:Repeater ID="rpSubscriptions" runat="server">
   <ItemTemplate>
      <asp:ImageButton ID="btnJoin" runat="server" 
                                       OnCommand="SelectPlan" 
                                       CommandArgument='<%# Eval("SubscriptionId") %>' 
                                       ImageUrl="~/images/join.png" />
      </ItemTemplate>
   </asp:Repeater>

Open in new window


This doesn't work!
     <myControls:SignUpForm ID="SignUpForm" SubscriptionID = '<%# Eval("SubscriptionId") %>' runat="server" />  

[Parent Codebehind] Not Working!
protected void SelectPlan(object sender, CommandEventArgs e)
{
       UserControls_SignUpForm form1 = new UserControls_SignUpForm();  
     
       form1.subscriptionId = e.CommandArgument.ToString();      
}
WorknHardrAsked:
Who is Participating?
 
Gary DavisConnect With a Mentor Dir Internet SvcsCommented:
Your SelectPlan() click event is allocating a new SignUpForm and setting  the subscriptionId property and then doing nothing with the new form.

You probably want to instead use the existing SignUpForm with ID SignUpForm instead of allocating a new one.

Then (I suspect) you probably want to do something with it.

Gary Davis
0
 
WorknHardrAuthor Commented:
Yes, how do I code that?
0
 
WorknHardrAuthor Commented:
THX
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.