Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,

I am using asp:updatepanel, asp:updatepanel contains imageslider, gridview etc.
and i am calling javascript function in pageload() for maintain the stage of imageslider but every time imageslider comes in it's starting position, like:
C#
function pageLoad()
                {
                $(function () {
                $('#mycarousel').jcarousel();
                });
                }


that's why i want to call this function according to gridview eventfire or any other option to call Jcarousel() according gridview control ID.

please help

Thanks
Shubham Gupta
Posted
Comments
Amit Jadli 28-Aug-15 8:21am    
you could call this function on item command event..

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>pageLoad();</script>", false);
Member 11449483 28-Aug-15 8:57am    
Sorry, But not working correctly.
ScriptManager.RegisterStartupScript(GridView_Project, GridView_Project.GetType(), "JavaScript", "<script type='text/javascript'>alert(hello);</script>", False)
alert is also not working so how i can accept pageload is working.
Thanks
Sanket Saxena 28-Aug-15 9:05am    
Don't understand why you are calling this ready function in pageLoad()?

1 solution

Hi,

The main problem area with your code is that you are using jQuerys ready method[^] with ASP.NET's UpdatePanel control.

This means, your jQuery method will run the 1st time your page is loaded (and the DOM is ready), but this event will not fire when a partial postback occurs.

There are a few methods to handle this, most involve wiring up the WebForms PageRequestManagers endRequest Event[^] to the jQuery's ready function.

In your instance, this would look something like:
JavaScript
//Your JS function ... 
function doCarousel(){
    $('#mycarousel').jcarousel();
}
//Call on jQuery ready ... 
$(document).ready(doCarousel);
//Call each time your UpdatePanel performs a partial postback ... 
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(doCarousel);



A good starting point to learn more about this approach, is contained in the following article:
Working with jQuery within the ASP.NET UpdatePanel[^]

... hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900