How do I retrieve the values entered in a nested control added dynamically to a webform?

Posted by Front Runner on Stack Overflow See other posts from Stack Overflow or by Front Runner
Published on 2010-04-03T03:38:27Z Indexed on 2010/04/03 3:43 UTC
Read the original article Hit count: 432

Filed under:
  1. I have a date range user control with two calendar controls: DateRange.ascx

    public partial class DateRange { public string FromDate { get { return calFromDate.Text; } set { calFromDate.Text = value; } }

    public string ToDate { get { return calToDate.Date; } set { calToDate.Text = value; } } }

  2. I have another user control in which DateRange control is loaded dynamically: ParamViewer.ascx

    public partial class ParamViewer { public void Setup(string sControlName) { //Load parameter control Control control = LoadControl("DateRange.ascx"); Controls.Add(control);

      DateRange dteFrom = (DateRange)control.FindControl("calFromDate");
      DateRange dteTo = (DateRange)control.FindControl("calToDate");
    

    }

    }

  3. I have a main page webForm1.aspx where ParamViewer.ascx is added

When user enter the dates, they're set correctly in DateRange control.

My question is how how do I retrieve the values entered in DateRange (FromDate and ToDate)control from btnSubmit_Click event in webForm1? Please advise. Thank you in advance.

© Stack Overflow or respective owner

Related posts about dynamic-usercontrols