Javascript not work after firing Updatepanel in asp.net

前端 未结 2 1243
情深已故
情深已故 2021-01-06 02:01

This is my website -> www.superim.ir Its template base is bootstrap and in nav menu I used below code for some effects!

$(\'.productbar .dropdown\').on(\'sho         


        
相关标签:
2条回答
  • 2021-01-06 02:37

    I faced the same problem. I got help from this link. Execute JavaScript when an UpdatePanel is updated

    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(
                            upPanel,
                            this.GetType(),
                            "MyAction",
                            "doMyAction();",
                            true);
    }
    
    1. The first parameter is the UpdatePanel
    2. The second parameter is a type parameter
    3. The third parameter, “MyAction”, is a key to identify the script.
    4. script itself.
    5. The final parameter is a flag to indicate whether the ScriptManager should wrap your code in script tags.
    0 讨论(0)
  • 2021-01-06 02:54

    This occurs due to the Partial Postback using UpdatePanel. The Events that you subscribe for the controls are rendered partially hence the events looses. To overcome this situation you need to rebind the control events.

    This is a common problem caused by mixing the conventional ASP.Net Ajax and jQuery events. When you do the partial postback, the DOM is recreated and the jQuery events are lost.

    Example:

    <script type="text/javscript">
        // bind the events (jQuery way)
            $(document).ready(function() {
                bindEvents();   
            });
        
            // attach the event binding function to every partial update
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(evt, args) {
                bindEvents();
            });
    <script/>
    

    Read More about PageRequest Manager on MSDN

    Here bindEvents() method contains all the script that you need to reload again after Partial Page Postback.

    Hope this helps you!

    0 讨论(0)
提交回复
热议问题