specificdynamically creating telerik controls error: Script controls may not be registered after PreRender

4 posts, 0 answers
  1. CBARS
    CBARS avatar
    55 posts
    Member since:
    Sep 2008

    Posted 13 Oct 2008 Link to this post

    Hi, i'm having a problem with dynamically creating controls(datetime picker specifically), i need the page to add a new control to the page every time a button is pressed.
    any help would be appreciated.

    Thanks
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Oct 2008 Link to this post

    Hi cbars,

    Can you please post a bit more info about how this control is created? I will gladly help you to resolve this issue.

    Best wishes,
    Vlad
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. CBARS
    CBARS avatar
    55 posts
    Member since:
    Sep 2008

    Posted 15 Oct 2008 Link to this post

    Hi,
    When the page loads i create a button control and then add it to the page in the Page load event. when i click the button it needs to add another row to the table which contains a datetime picker and another button. when i click the button it adds the first row but when i click the same button again it throws the error.
    Hope this helps.

    this is something like the page load and the privSubAddRow event:


    Panel

     

    panel;
    ImageButton imgBtn;
    TableCell tblCell;
    TableRow tblRow;
    Telerik.Web.UI.RadDateTimePicker dtp;

    tblRow = new TableRow();
    tblCell = new TableCell();
    panel = new Panel();
    imgBtn = new ImageButton();

     

     

    dtp = new Telerik.Web.UI.RadDateTimePicker();
    tblCell.Controls.Add(dtp);
    tblRow.Cells.Add(tblCell);


    tblCell = new TableCell();
    imgBtn.ID =

    "0|btn|" + intFieldID.ToString();
    imgBtn.Click += new ImageClickEventHandler(privSubAddRow);
    panel.Controls.Add(imgBtn);
    panel.Visible =
    true;
    tblCell.Controls.Add(panel);
    tblRow.Cells.Add(tblCell);

    tbl1.Rows.Add(tblRow);


     

    protected

     

    void privSubAddRow(object sender, EventArgs e)

     

    {

    Table

     

    tbl1;


     

    Panel panel;
    ImageButton imgBtn;
    TableCell tblCell;
    TableRow tblRow;
    Telerik.Web.UI.RadDateTimePicker dtp;

    tblRow = new TableRow();
    tblCell = new TableCell();
    panel = new Panel();
    imgBtn = new ImageButton();

    tbl1 = ((Table)((ImageButton)sender).Parent.Parent.Parent.Parent)

     

     

    dtp = new Telerik.Web.UI.RadDateTimePicker();
    tblCell.Controls.Add(dtp);
    tblRow.Cells.Add(tblCell);


    tblCell = new TableCell();
    imgBtn.ID =

    "0|btn|" + intFieldID.ToString();
    imgBtn.Click += new ImageClickEventHandler(privSubAddRow);
    panel.Controls.Add(imgBtn);
    panel.Visible =
    true;
    tblCell.Controls.Add(panel);
    tblRow.Cells.Add(tblCell);

    tbl1.Rows.Add(tblRow);
    }


    Regards,
    Sean Schoeman

  4. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 23 Oct 2008 Link to this post

    Hello Sean,

    When you place more than one server control within the same naming container with same ID there will be an  error raised. If you place ajax enabled controls when the page loads most probably javascript errors will be raised, because the framework won't be able to handle their client objects properly.

    For your convenience I've prepared a sample project which is one possible solution in the scenario you have.
    You can find it attached to this post.

    Kind regards,
    NikR
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top