日期:2014-05-18  浏览次数:20367 次

jQuery 调用用户控件后台方法失败
JS代码
JScript code

$('#dialog').dialog
        (
                {
                    autoOpen: false,
                    width: 700,
                    modal: true,
                    buttons:
                    {

                        "Ok": function() 
                        { 
                        //校验输入项
//                        if (!valDialog(this))
//                          return;
                        var sType=$(".ApplyControl_ddlType").val();
                        var sFromDate=$(".ApplyControl_fromdatepicker").val();
                        var sFromHours=$(".ApplyControl_ddlTimeF").val();
                        var sToDate=$(".ApplyControl_todatepicker").val();
                        var sToHours=$(".ApplyControl_ddlTimeT").val();
                        var sDays=$(".ApplyControl_tbday").val();
                        var sHours=$(".ApplyControl_tbhours").val();
                        var sRemark=$(".ApplyControl_remark").val();
                          
                        $.ajax
                            ({
                        type: "post",
                        contentType: "application/json;charset=utf-8",
                        url: "ApplyControl.ascx/ApplyVacation",
                        //data: "{StrType:'" + sType + "', StrFromDate:'" + sFromDate + "'}",
                        data: "{StrType:'" + sType + "', StrFromDate:'" + sFromDate + "',StrFromHour:'" + sFromHours + "',StrToDate:'" + sToDate + "', StrToHour:'" + sToHours + "', StrDays:'" + sDays + "', StrHours:'" + sHours + "', StrRemark:'" + sRemark + "'}",
                        dataType: "json",
                        success: function (result) 
                        {
                            alert(result.d);
                            if(result.d==""){$this.dialog("close");alert("#");}
                            else {alert(result.d);}
                         },
                        });
                         },


                        "Cancel": function () { $(this).dialog("close");}
                     }
               });



用户控件 后台方法
C# code
 public static string ApplyVacation(string StrType, string StrFromDate, string StrToDate,string StrFromHour,string StrToHour, string StrDays,string StrHours, string StrRemark)
    {
        new ITDateClient().InsertVacation(StrType, StrFromDate, StrToDate, StrFromHour, StrToHour, StrDays,StrHours,StrRemark);

        return "";
    }



点击OK button 无反应,求教大家.....

------解决方案--------------------
自己调试先一下,是否调用到了后台的方法???

出错的代码是那行??
------解决方案--------------------
url: "ApplyControl.ascx/ApplyVacation",
这样可以直接访问这个方法么?

你还是先改成 url: "ApplyControl.ascx" 看看这个控件的Page_Load方法会不会执行。
------解决方案--------------------
ApplyControl.ascx?method=ApplyVacation

context.Response.ContentType = "application/json";
string method = context.Request["method"];
switch (method)
{
case "login":
ApplyVacation(context);
break;
}
context.Request.Form["StrType"]

------解决方案--------------------
在前台 输出 值 跟踪一下