Nikhil D
Nikhil D

Reputation: 2509

btn is click two times after async postback

i am doing async postback using updatepanel. after async postback button is click two times.I dont know why I'm using jQuery to wire up some mouseover effects on elements that are inside an UpdatePanel. The events are bound in $(document).ready

    <script type="text/javascript">
        window.onload = body_load;
        function body_load()
        {
           BindEvents();
        }
        function BindEvents()
        {
            $(function ()


{$(".csstablelisttd").mousedown(function (e)
                {//mouse down code});
                    $("#contentPlaceHolderMain_btnFix").click(function (e)
                    {alert("Alert");//here alert is generate two times an then postback occurs
                       //btn click code
                    }
                }
            }
        </script>

<asp:UpdatePanel ID="updatePanelTableAppointment" runat="server">
                        <ContentTemplate>
     <table id="table" runat="server">
         //table data
        </table>

<script type="text/javascript">Sys.Application.add_init(body_load);
</script>
                    </ContentTemplate><Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnFix" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>

Upvotes: 0

Views: 344

Answers (2)

onof
onof

Reputation: 17377

You are attaching events twice: at loading of the page and after postback. You need to reset the handler, if you have to change the event handler

            function BindEvents()
            {
               $(function () {
                  $(".csstablelisttd").unbind('mousedown');
                  $("#contentPlaceHolderMain_btnFix").unbind('click');

                  $(".csstablelisttd").mousedown(function (e)
                      {//mouse down code});                                     
                  $("#contentPlaceHolderMain_btnFix").click(function (e)
                      {alert("Alert"); });
                }
            }

Upvotes: 0

Rab
Rab

Reputation: 35582

you are calling body_load two times

here

 window.onload = body_load;

and here

Sys.Application.add_init(body_load);

which cause it to click two times

Upvotes: 1

Related Questions