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

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

3 Answers 77 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
CBARS
Top achievements
Rank 2
CBARS asked on 13 Oct 2008, 10:24 AM
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

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Oct 2008, 05:45 AM
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.
0
CBARS
Top achievements
Rank 2
answered on 15 Oct 2008, 08:00 AM
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

0
Nikolay Rusev
Telerik team
answered on 23 Oct 2008, 07:59 AM
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.
Tags
Calendar
Asked by
CBARS
Top achievements
Rank 2
Answers by
Vlad
Telerik team
CBARS
Top achievements
Rank 2
Nikolay Rusev
Telerik team
Share this question
or