I made a survey tool with a rad rotator for an Ipad website, I am filling the rotator with RadioButtonlists and RadRating item dynamicly and the last part I add a button to say save survey. I loop though all the controls and I can not find any of the dynamic controls I even tried to use page.findcontrol and I can not find them, can anyone help out with this?
thanks!
Here is my code:
thanks!
Here is my code:
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using Telerik.Web.UI; using OSweb.Admin.DataTypes; namespace OSweb.Controls { public partial class DisplayQuestions : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { RadRotator1.ItemTemplate = new RadRotatorTemplate(); RadRotator1.DataSource = CreateRotatorData(Convert.ToInt32(Session["DealerId"].ToString()), Convert.ToInt32(Session["GroupId"].ToString())); RadRotator1.DataBind(); } else { Button bt = (Button)Page.FindControl("ButtonSubmitSurvey"); LabelTest.Text = bt.Text; } } private List<Questions> CreateRotatorData(Int32 DealerId, int GroupId) { List<Questions> lq = new List<Questions>(); using (OSWEB_GenericRemittanceEntities OSWEBe = new OSWEB_GenericRemittanceEntities()) { var qg = (from l in OSWEBe.QuestionGroups where (l.GroupID == GroupId) && (l.DealerId == DealerId) select l.GroupID).FirstOrDefault(); if (qg != null) { var q = (from l in OSWEBe.GroupOfQuestions where (l.GroupID == GroupId) select l); foreach (GroupOfQuestion goq in q) { Questions qs = new Questions(); qs.QuestionText = goq.Question.QuestionText; qs.QuestionType = goq.Question.QuestionType; qs.QuestionId = Convert.ToInt32(goq.QuestionID); lq.Add(qs); } Questions qsEnd = new Questions(); qsEnd.QuestionType = "End"; lq.Add(qsEnd); } } return lq; } } public class RadRotatorTemplate : ITemplate { public RadRotatorTemplate() { } public void InstantiateIn(Control container) { HtmlGenericControl wrapper = new HtmlGenericControl("div"); wrapper.DataBinding += new EventHandler(wrapper_DataBinding); container.Controls.Add(wrapper); } void wrapper_DataBinding(object sender, EventArgs e) { HtmlGenericControl wrapper = sender as HtmlGenericControl; RadRotatorItem item = wrapper.NamingContainer as RadRotatorItem; wrapper.InnerHtml = string.Format("<strong>{0}</strong>", ((Questions)item.DataItem).QuestionText); switch (((Questions)item.DataItem).QuestionType) { case "YesNo": { RadioButtonList rbl = new RadioButtonList(); rbl.ID = ((Questions)item.DataItem).QuestionId.ToString(); ListItem liYes = new ListItem(); liYes.Text = "Yes"; rbl.Items.Add(liYes); ListItem liNo = new ListItem(); liNo.Text = "No"; rbl.Items.Add(liNo); wrapper.Controls.Add(rbl); break; } case "Rate": { RadRating rr = new RadRating(); rr.ID = ((Questions)item.DataItem).QuestionId.ToString(); rr.ItemCount = 10; wrapper.Controls.Add(rr); break; } case "Multi": { Int32 qId = ((Questions)item.DataItem).QuestionId; RadioButtonList rbl = new RadioButtonList(); rbl.ID = ((Questions)item.DataItem).QuestionId.ToString(); using (OSWEB_GenericRemittanceEntities OSWEBe = new OSWEB_GenericRemittanceEntities()) { var answers = (from a in OSWEBe.Answers where a.QuestionID == qId select a); foreach (Answer a in answers) { ListItem li = new ListItem(); li.Text = a.AnswerText; li.Value = a.AnswerID.ToString(); rbl.Items.Add(li); } wrapper.Controls.Add(rbl); } break; } case "End": { Button bt = new Button(); bt.Text = "Submit Survey"; bt.ID = "ButtonSubmitSurvey"; bt.Click += new System.EventHandler(bt_Click); wrapper.Controls.Add(bt); break; } } } private void bt_Click(object Sender, EventArgs e) { } } }