This is a migrated thread and some comments may be shown as answers.

How to add RadControls to dynamic created table

0 Answers 83 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Saif
Top achievements
Rank 1
Saif asked on 23 Jan 2019, 06:48 AM

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 new to telerik controls.

 

Code Behind: 

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);
}

 

No answers yet. Maybe you can help?

Tags
ListView
Asked by
Saif
Top achievements
Rank 1
Share this question
or