Getting Javascript function to run on ASP.Net repeater DataBind
I have an ASP.net repeater on my page which creates a load of listitems. I'm also using the JQuery UI Slider plugin to generate a slider from a div thats contained in some of the list items. So I have a javascript function called initSliders() that runs when the page has loaded which crea开发者_运维问答tes the sliders. This works fine.
The Repeater is inside an Ajax UpdatePanel which updates every 10 seconds. The repeater is rebound on every iteration. This is where the problem happens, on the reresh the sliders dissapear. I believe this is because the repeater is being re-generated so I think I need a way of calling the javascript initSliders() function after each time the repeater has loaded.
Any ideas how I would do that?
You're right. On partial postback your slider is removed and you have to recreate it on every refresh.
A way of doing this could be adding a snippet like this on Page_Load
string script = //SCRIPT THAT CREATES THE SLIDER
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),
"SLIDER", script, true);
EDIT
The partial update response is set to the innerHTML of a div control and because of that no inline javascript code within the update panel will work on refresh.
That's why you need to register the script using ScriptManager
A more detailed explanation here
精彩评论