WebMethod功能后按钮单击不起作用

时间:2017-09-08 09:18:44

标签: c# jquery asp.net ajax

在我的网页上,我使用jquery和ajax调用C#函数来填充另一个enter image description here的下拉列表 下拉分支根据区域和员工的选择填充并选择分支。它工作正常但是按钮点击后不能正常工作。有人请告诉我为什么这个按钮点击不起作用?
[没有选择下拉选项时按钮单击工作] 我的代码看起来像这样:

Jquery的

<script src="jquery-1.11.1.min.js"></script>
<script type="text/javascript">


    $(function () {

        $('#<%= ddZone.ClientID %>').change(function () {  
            $.ajax({
                type: "POST",
                url: "Reports.aspx/BranchFill",
                data: "{'Zone':'" + $("[id*=ddZone] option:selected").text() + "'}",
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: OnSuccess,
                     failure: function (response) {
                         alert(response.d);
                     }

           });
            function OnSuccess(response) {

                var ddlBranch = $("[id*=ddBranch]");
                ddlBranch.empty().append('<option selected="selected" value="0">--Select--</option>');
                $.each(response.d, function () {
                    ddlBranch.append($("<option></option>").val(this['Value']).html(this['Text']));
                });

                if (response.d == "false") {
                         alert("Not found");                           
                     }
                 }

        });


    $('#<%= ddBranch.ClientID %>').change(function () {  
        $.ajax({
            type: "POST",
            url: "Reports.aspx/EmployeeFill",
            data: "{'Branch':'" + $(this).val() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccess,
            failure: function (response) {
                alert(response.d);
            }

        });
        function OnSuccess(response) {

            var ddlEmployee = $("[id*=ddEmployee]");
            ddlEmployee.empty().append('<option selected="selected" value="0">--Select--</option>');
            $.each(response.d, function () {
                ddlEmployee.append($("<option></option>").val(this['Value']).html(this['Text']));
            });

            if (response.d == "false") {
                alert("Not found");                           
            }
        }

    });

   });


</script>

C#

 [System.Web.Services.WebMethod(EnableSession = true)]
    public static Object BranchFill(string Zone)
    {
        string result = string.Empty;
        var obj = new Reports();
        List<ListItem> Branch = new List<ListItem>();

        DataTable dt = obj.CS.StaticZoneBranch(Zone, "", "SelectBranch");

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Branch.Add(new ListItem
                {
                Text  = dt.Rows[i]["Name"].ToString(),
                Value  = dt.Rows[i]["Code"].ToString()
                });                                   
            }
            return Branch;
        }
        else
        {
            return "false";
        }

    }

    [System.Web.Services.WebMethod(EnableSession = true)]
    public static Object EmployeeFill(string Branch)
    {
        string result = string.Empty;
        var obj = new Reports();
        List<ListItem> Employee = new List<ListItem>();

        DataTable dt = obj.CS.StaticZoneBranch("", Branch, "SelectEmployee");

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Employee.Add(new ListItem
                {
                    Text = dt.Rows[i]["Name"].ToString(),
                    Value = dt.Rows[i]["Employee Id"].ToString()
                });
            }
            return Employee;
        }
        else
        {
            return "false";
        }
    }

按钮单击(不起作用)

protected void Button1_Click(object sender, EventArgs e)
    {
        ReportClass RC = new ReportClass();
        if (ddZone.SelectedValue !="0")
        {
            RC.Zone = ddZone.SelectedValue;
            RC.Branch = ddBranch.SelectedValue;
            RC.EmployeeId = ddEmployee.SelectedValue;
            Report = RC.GetReport();
        }
    }

为什么这个点击功能不起作用,请帮我知道..

0 个答案:

没有答案