473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Dynamic Javascript not working in Update Panel

Hi All,

I am working on an application where i have got, a content page within a Master Page. I have placed a gridview on the page. This gridview has three fields, one of them is TemplateFied, a BoundFiled and a CommandField, along with paging enabled in the gridview.

In the template field i am creating a dynamic javascript on RowDataBound.

I wanted to place this gridview in Update panel so that it doesnot re-loads when command is clicked or page is changed.

I placed a scriptmanager and an update panel, and placed the grid in it. Now my command field works only once and not more, and same is true for the javascript, it doesnt gets initilized.

Can any one help me!
Apr 20 '10 #1

✓ answered by Frinavale

I can't check out that link right now and probably wont be able to check it out until Sunday night at the earliest.

But, you know how you're adding the script in your MasterPage?
Use the ScriptManager to register this script instead.

There are functions that let you do this dynamically or you can do it right in the ScriptManger's <scripts> section.

Essentially you want to register that script with the page every postback (asynchronous postback or not) or else this script will stop working.

6 9377
Frinavale
9,735 Expert Mod 8TB
How are you registering the dynamic JavaScript?

-Frinny
Apr 21 '10 #2
Actually i am displaying songs within gridview, with a music player in the templateField that needs javascript to work. I am fetching playlist out of an xml file and bind the grid to that xml. I have got a long list of songs. thats why i have enabled paging on the gridview. And there is also a buttonField "Add to play list". When i place this grid within UpdatePanel, for the first page its all fine. When i go to next page Using GridView COmman, Musc player vanishes. Surely a postback occurs and javascript doesnt execute. The same is the case when i click on buttonField.

See this here is my html for Gridview:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="gvSongs" runat="server" AutoGenerateColumns="False" 
  2.         HorizontalAlign="Center" onrowcommand="gvSongs_RowCommand" 
  3.         onrowdatabound="gvSongs_RowDataBound" Width="100%" DataKeyNames="id" 
  4.     AllowPaging="True" onpageindexchanging="gvSongs_PageIndexChanging">
  5.            <PagerSettings Mode="NextPreviousFirstLast" />
  6.            <Columns>
  7.                <asp:TemplateField></asp:TemplateField>
  8.                <asp:BoundField DataField="Title" HeaderText="Title" />
  9.                <asp:ButtonField CommandName="Add" Text="Add to Playlist" />
  10.            </Columns>
  11.            <PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" />
  12.        </asp:GridView>
And Here is the RowDataBound Method, where my dynamic Javascript is being created:
Expand|Select|Wrap|Line Numbers
  1.  protected void gvSongs_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
  2.         {
  3.             if (e.Row.DataItem != null)
  4.             {
  5.                 Song song = (Song)e.Row.DataItem;
  6.                 e.Row.Cells[0].Text = "<p id=\"" + song.Id + "\">Song could not be played</p> <script type=\"text/javascript\">AudioPlayer.embed(\"" + song.Id + "\", {soundFile: \"" + song.Src + "\", titles: \"" + song.Title + "\" });</script>";
  7.             }
  8.         }
I am adding javascript for audio player like dis on my Master page:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="http://mydomain.com/audio-player/audio-player.js"></script>  
  2.          <script type="text/javascript">  
  3.              AudioPlayer.setup("http://mydomain.com/audio-player/player.swf", {  
  4.                  width: 290  
  5.              });  
  6.          </script>
Apr 22 '10 #3
Frinavale
9,735 Expert Mod 8TB
I'm not sure how the GridView, the play list, and the player interact with one another.

But, by the sounds of it, I think you want to place the GridView into it's own UpdatePanel so that paging through the options happens asynchronously.

You may have a problem though when you click the "add to playlist" button.
I'm not sure how you are adding the items to the play list or how the play list and the player are tied together....so my suggestion may not be feasible for you.



-Frinny
Apr 22 '10 #4
Hey frinney look at rowdatabound. Thats is how i am setting music player for invidual songs in row, then there is song title and finally add to play list button.

i have called the javascript file in my master page. as you can see and then using it in my gridview, and it work fine.

I dont have any confusion in adding songs to play list. Every thing is working fine.
But the problem occurs when i place my datagrid in UpdatePanel, that i dont want it to flicker or reload when user clicks on add to playlist or moves to next page. Now after placing it in update panel on first page load evrything comes fine. when i click on add to playlist button, or move to next page button, then javascript stops working and my music player vanishes.

Actually its a facebook application.
Here is the link, http://apps.facebook.com/musicforu/Default.aspx?
Apr 23 '10 #5
Frinavale
9,735 Expert Mod 8TB
I can't check out that link right now and probably wont be able to check it out until Sunday night at the earliest.

But, you know how you're adding the script in your MasterPage?
Use the ScriptManager to register this script instead.

There are functions that let you do this dynamically or you can do it right in the ScriptManger's <scripts> section.

Essentially you want to register that script with the page every postback (asynchronous postback or not) or else this script will stop working.
Apr 23 '10 #6
great!
This worked!
I used ScriptManager to register my Javascript blocks and it really worked.

Thanks brother.
Apr 23 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
2
by: intrepid_dw | last post by:
All I am writing a C# WinForms application which is giving me some problems. The application consists of a form containing an empty Tab control to which TabPages are added dynamically (at...
1
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1"...
2
by: rodchar | last post by:
hey all, how can i get javascript procedure to execute as the very last thing before the page is rendered? Background: I have a DIV element inside an update panel. I am setting the scrollLeft...
5
by: Kursat | last post by:
Hi, I want to add new collapsable panel items using java script at client side. Is this possible to create Ajax components like collapsable panel without server round trip? Thanks in advance.
1
by: gabe | last post by:
How do you call a client side javascript callback method after an update panel has posted back to the server? I have two update panels (A + B) with a gridview in each panel. GridView B has a...
5
by: HockeyFan | last post by:
We have an update panel that has a gridview with checkboxes and other items in each row. We went to the RowCreated event in the codebehind, to set an attribute on a checkbox in each row, to...
5
by: voidinutah | last post by:
Hello, I'm new to .NET and was trying to find a solution for having a button control do a post back then execute a javascript function. When the button is clicked a post back occurs to save...
10
dj12345
by: dj12345 | last post by:
Hi, (Asp.net + Ajax) I am creating a page which will fetch data from server without postbak of a page.. I have 2 controls on this page TextBox and Lable. I have assigned TextBoxWatermark...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.