点击事件不会激发 [英] click event not fireing

查看:68
本文介绍了点击事件不会激发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我将JavaScript代码添加到程序中,按钮OnClick事件没有触发,任何想法为什么会发生这种情况?,我已经通过了进度条的C#代码,当点击它时会加载进度条。我想要知道为什么按钮点击事件没有解雇。





** HTML和JavaScirpt代码**:

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
    }

推荐答案

.updateProgressbar = function( ){
//为当前进度调用PageMethod
PageMethods.OperationProgress(函数(结果){
//更新进度
.updateProgressbar = function () { //Calling PageMethod for current progress PageMethods.OperationProgress(function (result) { //Updating progress


(#progressbar ).progressbar('value',result.progress)
//如果操作完成
if(result.progress == 100){
//启用按钮
("#progressbar").progressbar('value', result.progress) //If operation is complete if (result.progress == 100) { //Enable button


(\"#Confirm_btn\").attr('disabled','');
}
//如果不是
else {
//重置计时器
setTimeout(
("#Confirm_btn").attr('disabled', ''); } //If not else { //Reset timer setTimeout(


这篇关于点击事件不会激发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆