Click here to Skip to main content
15,891,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had created rad dynamic controls which consists of(textbox, ddl, combobox etc..) and also created dynamic rad wizardsteps, every wizardstep contains a dynamic table.

I want insert those dynamic rad controls into wizardstep table, to achieve this i used sessions but its giving a exception says Script controls may not be registered after PreRender..

When i tried to insert these controls in static asp table it works fine, while adding to a dynamic table i am getting this issue. What i had done wrong, how can i resolve this issue.

Please guide me i am quite new to programming.

What I have tried:

   protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           GenerateWizardSteps(2);
           RadListView1.DataSource = GetDatatable();
           RadListView1.DataBind();
       }
       else
       {
           RecreateControls("rtb", "RadTextBox");
       }
   }
   public DataTable GetDatatable()
   {
       DataTable dt = new DataTable();
       dt.Columns.Add("Label");

       dt.Rows.Add("RadTextBox");
       dt.Rows.Add("RadComboBox");
       dt.Rows.Add("RadDateTimePicker");
       dt.Rows.Add("RadDropDownList");
       dt.Rows.Add("RadDatePicker");
       dt.Rows.Add("RadNumericTextBox");
       dt.Rows.Add("RadToggleButton");
       dt.Rows.Add("RadBinaryImage");
       return dt;
   }

   //Creating WizardSteps
   public void GenerateWizardSteps(int formID)
   {
       RadWizardStep step;

       step = new RadWizardStep();
       step.ClientIDMode = ClientIDMode.Static;
       step.ID = "step_" + i.ToString();
       controlTbl = new Table();
       controlTbl.ClientIDMode = ClientIDMode.Static;
       controlTbl.ID = "controlTable_" + i.ToString();
       Session["myTable"] = controlTbl;
       step.Controls.Add(controlTbl);
       wizardControl.WizardSteps.Add(step);
    }
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
   {
       string commandText = e.Argument.ToString().Trim();
       string[] splitdata = commandText.Split('&');
       commandText = splitdata[0];
       string controlName = splitdata[1];
       switch (controlName)
       {
           case "RadTextBox":
               int cnt1 = FindOccurence("rtb") + 1;
               DynamicControls dcTextBox = new DynamicControls();
               TableCell txtlblRad = dcTextBox.Controlscreation("RadLabel", "", cnt1, cnt1, "Text Box:", "", 0);
               TableCell txtRad = dcTextBox.Controlscreation("RadTextBox", "", cnt1, cnt1, "", "", 0);
               TableRow txtRow = new TableRow();
               txtRow.Cells.Add(txtlblRad);
               txtRow.Cells.Add(txtRad);
               Table controlTbl = Session["myTable"] as Table;
               controlTbl.Rows.Add(txtRow);
               //Table1.Rows.Add(txtRow);

               break;
        }
   }
   private void RecreateControls(string ctrlPrefix, string ctrlType)
   {
       string[] ctrls = Request.Form.ToString().Split('&');
       int cnt = FindOccurence(ctrlPrefix);
       if (cnt > 0)
       {
           for (int k = 1; k <= cnt; k++)
           {
               for (int i = 0; i < ctrls.Length; i++)
               {
                   if (ctrls[i].Contains(ctrlPrefix + "_" + k.ToString()))
                   {

                       if (ctrlType == "RadTextBox")
                       {
                           DynamicControls dcTextBox = new DynamicControls();
                           TableCell txtlblRad = dcTextBox.Controlscreation("RadLabel", "", k, k, "TextBox:", "", 0);
                           TableCell txtRad = dcTextBox.Controlscreation("RadTextBox", "", k, k, "", "", 0);
                           TableRow txtRow = new TableRow();
                           txtRow.Cells.Add(txtlblRad);
                           txtRow.Cells.Add(txtRad);
                           Table controlTbl = Session["myTable"] as Table;
                           controlTbl.Rows.Add(txtRow);
                       }
                          break;
                   }
               }
           }
       }
   }

   private int FindOccurence(string substr)
   {
       string reqstr = Request.Form.ToString();
       //return (((reqstr.Length - reqstr.Replace(substr, "").Length) / substr.Length) / 2);
       return ((reqstr.Length - reqstr.Replace(substr, "").Length) / substr.Length);
   }
Posted
Updated 23-Jan-19 1:54am
Comments
[no name] 22-Jan-19 12:21pm    
ASP.Net ain't that smart; that's rich client stuff (i.e. WPF)

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900