Problems with sending javascript from dynamically loaded control

  • Thread starter Jesper Lund Stocholm
  • Start date
J

Jesper Lund Stocholm

I have problems with sending javascript to the client from a dynamically
loaded usercontrol.

I have a single page that dynamically loads controls into a table cell in
a HTML-table. For one of these controls I would like to add some
javascript to the page loading my control. The problem is only - nothing
happens. The code that loads my usercontrol from my ASPX-page is:

tdContent.Controls.Add(Page.LoadControl(contentControl));

Where "tdContent" is a table cell and the variable "contentControl" is
the physical path to my usercontrol's ASCX-file.

I would think that I could do it like this (from my ASCX-file):

protected override void OnInit(EventArgs e)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(), "key", "alert('foo');", true);
base.OnInit(e);
}

Som alas nothing happens. I have a gut feeling that it is due to the fact
that the HTML of my ASPX-page has been created when I try to add to it
from my usercontrol, but I have found nowhere in the doc that could bring
me closer to a explanation.

Any of you guys have an idea of what to do?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top