Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arachnid - 05 Oct 2007 10:29 GMT
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.

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

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

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

       <asp:UpdateProgress ID="UpdateProgress1" runat="server"
DisplayAfter="0">
           <ProgressTemplate>
               delay............................
           </ProgressTemplate>
       </asp:UpdateProgress>
</form>
<script language="javascript" type="text/javascript">
function pageLoad(){
alert($get('p').innerHTML);
}

</script>

</body>
</HTML>
---------------- CODE BEHIND --------------------

 protected void Button1_Click(object sender, EventArgs e)
   {
       string str = "<div id='Update'>HI</div>";
        str += "<script language='Javascript' type='text/
javascript'>document.getElementById('Update').innerHTML='latest
updated hiiiiiiiiiiii!!!';</script>";
       System.Threading.Thread.Sleep(3000);
       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
Patrice - 05 Oct 2007 12:02 GMT
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).

> Hi all,
>
[quoted text clipped - 77 lines]
>
> - Arachnid

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.