AJAX Problem. JavaScript not working if i push it to Updatepanel's content.



Hi all,

I am trying something using ASP.NET AJAX.
Using postback i am adding a JavaScript snippet and a DIV inside a
panel in UPdatePanel.The HTML is shown. The Javascript is written too.
But JavaScript is not working.

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:ScriptReference Path="FusionCharts.js" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<script language="javascript" type="text/javascript">
var XML="<chart/>";

<asp:panel ID="p" runat="server" Height="262px"
please click on the button</asp:panel>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Button" />

<asp:UpdateProgress ID="UpdateProgress1" runat="server"
<script language="javascript" type="text/javascript">
function pageLoad(){


---------------- CODE BEHIND --------------------

protected void Button1_Click(object sender, EventArgs e)
string str = "<div id='Update'>HI</div>";
str += "<script language='Javascript' type='text/
updated hiiiiiiiiiiii!!!';</script>";
p.Controls.Add(new LiteralControl(str));



I am using the general ScriptManager coltrol and UpdatePanel that has
a PANEL having an id 'p'.
From the server side postback i am changing this panel's HTML to

<div id='Update'>Hi</div><script language='Javascript' type='text/
javascript'> document.getElementById('Update').innerHTML='latest
updated hiiiiiiiiiiii!!!';</script>

I can see the div being parsed by the browser. But the <script> is not
taken care of by the browser.

PLease, please, please help me out of this.

Am i going wrong somewhere? IS there any way out?

Please help me.

- Arachnid




Not, familiar yet with AJAX but looks like an expected behavior to me.

Basically you just replace a part of your page with this cript. But i'm not
sure the script is supposed to run. You could try as well with a plain good
old HTML page. Just programmtically add some script in the already loaded
page. IMO it won't run automatically the script as it would if the page were
loaded with this script already in place.

You may want to explain what you are trying to do (in this case I'm not sure
why you don't change directly the markup).

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