Click here to Skip to main content
12,698,600 members (24,466 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
once i add the JavaScript code into the program, the button OnClick event is not firing, any ideas why this occurs?,I have passed the C# code for the progress bar and when clicked it loads the progress bar.I would like to know why button click event is not firing.


**HTML and JavaScirpt Code**:
<asp:Button ID="Confirm_btn" CssClass="confirmBtn" runat="server" Text="Generate Presentation" UseSubmitBehavior="true"
                              ClientIDMode="Static" OnClick = "Confirm_Click" />

                             </td></tr>
                         <tr><td colspan="2" align="center">
                            <div id="progressbar" style="width:500px"></div>
                            </td></tr>
                            </table>
                        </div>

                        <asp:Label ID="error" runat="server" ClientIDMode="Static"
                            EnableViewState="False" Font-Names="Arial"></asp:Label>
                    </center>
                </div>

    </asp:Content>
      <asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
        <script type="text/javascript">
            $.updateProgressbar = function () {
                //Calling PageMethod for current progress
                PageMethods.OperationProgress(function (result) {
                    //Updating progress
                    $("#progressbar").progressbar('value', result.progress)
                    //If operation is complete
                    if (result.progress == 100) {
                        //Enable button
                        $("#Confirm_btn").attr('disabled', '');
                    }
                    //If not
                    else {
                        //Reset timer
                        setTimeout($.updateProgressbar, 500);
                    }
                });
            };

            $(document).ready(function () {
                //Progressbar initialization
                $("#progressbar").progressbar({ value: 0 });
                //Button click event
                $("#Confirm_btn").click(function (e) {
                    e.preventDefault();
                    //Disabling button
                    $("#Confirm_btn").attr('disabled', 'disabled');
                    //Making sure that progress indicate 0
                    $("#progressbar").progressbar('value', 0);
                    //Call PageMethod which triggers long running operation
                    PageMethods.Operation(function (result) {
                        if (result) {
                            //Updating progress
                            $("#progressbar").progressbar('value', result.progress)
                            //Setting the timer
                            setTimeout($.updateProgressbar, 500);
                        }
                    });
                });
            });
        </script>
    </asp:Content>

**C# Code For the ProgressBar**:


    /// <summary>
        /// PageMethod for triggering long running operation
        /// </summary>
        /// <returns></returns>
        [System.Web.Services.WebMethod(EnableSession = true)]
        public static object Operation()
        {
            HttpSessionState session = HttpContext.Current.Session;

            //Separate thread for long running operation
            ThreadPool.QueueUserWorkItem(delegate
            {
                int operationProgress;
                for (operationProgress = 0; operationProgress <= 100; operationProgress = operationProgress + 2)
                {
                    session["OPERATION_PROGRESS"] = operationProgress;

                    Thread.Sleep(1000);
                }
            });

            return new { progress = 0 };
        }

        /// <summary>
        /// PageMethod for reporting progress
        /// </summary>
        /// <returns></returns>
        [System.Web.Services.WebMethod(EnableSession = true)]
        public static object OperationProgress()
        {
            int operationProgress = 0;

            if (HttpContext.Current.Session["OPERATION_PROGRESS"] != null)
                operationProgress = (int)HttpContext.Current.Session["OPERATION_PROGRESS"];

            return new { progress = operationProgress };
        }
    }

**C# Code for Button Click Event**:


    protected void Confirm_Click(object sender, EventArgs e)
    {
       // my process run here
    }
Posted 20-Feb-13 2:21am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

JQuery, in some cases only, blocks the event somehow. Last time I encountered this I solved it by creating a static webmethod in a dummy aspx page and call that webmethod via a JSON call. Although it worked I still consider it a dirty solution, but if all else fails, it might be an option.

I'm pretty sure that you can re-fire or unblock the event somehow (like returning true or false in a function maybe?), but there fore you'll need to find the culprit blocking the event.

Hope this at least gives you some ideas.
  Permalink  
Comments
priyesh patel 20-Feb-13 9:18am
   
isnt there any other way of doing this
V. 20-Feb-13 9:20am
   
Not that I have found, else I would have told you. Maybe someone else has a better option.
priyesh patel 20-Feb-13 9:30am
   
thanks for the help.. thats not a solution that I will use because its not safe to use because other problem may occur in the future
V. 20-Feb-13 11:14am
   
Well at least you know JQuery blocks events in some cases. That at least should give you some direction. :-)
Best of luck.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100