最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JS Error:Cannot call method of null - Stack Overflow

programmeradmin3浏览0评论

I have the following method in a js file in ASP.Net web project. This method is giving the error Cannot call method 'split' of null

 function loadUser_InfoCallBack(res)
    {
    var ret=res.value;
    var senderGUID = ret.split(';')[0];
    var senderText = ret.split(';')[1];

    if(senderGUID.Length>0)
    {
    $('hiddenSender.value')=senderGUID;
    $('hiddenText.value')=senderText;
    }

}

Can anybody suggest the reasons for this error..


where the code for the getOwnerInfo method is below

[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string getOwnerInfo()
        {
            string strReturn = ";";

            if (Session["User_GUID"] != null)
            {
                string strUserGUID = Session["User_GUID"].ToString();

                string strIndGUID = "";
                string strIndName = "";

                //Initialize Connection String
                cns = DAL360.Common.getConnection(HttpContext.Current.Session["Server"].ToString(), HttpContext.Current.Session["Database"].ToString());

                DAL360.std_UserRepositoryArtifacts.std_UserRepository userRep = new DAL360.std_UserRepositoryArtifacts.std_UserRepository(cns);
                std_User user = userRep.Getstd_UserByusr_GUID(new Guid(strUserGUID));


                DAL360.std_IndividualRepositoryArtifacts.std_IndividualRepository indRep = new DAL360.std_IndividualRepositoryArtifacts.std_IndividualRepository(cns);
                std_Individual ind = indRep.Getstd_IndividualByind_GUID(new Guid(user.usr_ind_GUID.ToString()));

                if (ind != null)
                {
                    strIndGUID = ind.ind_GUID.ToString(); 

                    strIndName = ind.ind_Prefix + " " + ind.ind_FirstName + " " + ind.ind_MiddleName + " " + ind.ind_LastName;

                    DAL360.std_IndividualAddressRepositoryArtifacts.std_IndividualAddressRepository iadRep = new DAL360.std_IndividualAddressRepositoryArtifacts.std_IndividualAddressRepository(cns);
                    List<std_IndividualAddress> iadList = iadRep.GetAllFromstd_IndividualAddressByIndGUID(ind.ind_GUID);

                    if (iadList != null && iadList.Count > 0)
                    {
                        std_IndividualAddress iad = iadList[0];
                        strIndName += " (" + iad.iad_City + ", " + iad.iad_State + ")";
                    }
                }


                strReturn = strIndGUID + ";" + strIndName;

            }//end if statement


            return strReturn;

        }

And this method is in the code behind page of frmHome.aspx page. And I get the error when i try to open the page frmHome.aspx

I have the following method in a js file in ASP.Net web project. This method is giving the error Cannot call method 'split' of null

 function loadUser_InfoCallBack(res)
    {
    var ret=res.value;
    var senderGUID = ret.split(';')[0];
    var senderText = ret.split(';')[1];

    if(senderGUID.Length>0)
    {
    $('hiddenSender.value')=senderGUID;
    $('hiddenText.value')=senderText;
    }

}

Can anybody suggest the reasons for this error..


where the code for the getOwnerInfo method is below

[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string getOwnerInfo()
        {
            string strReturn = ";";

            if (Session["User_GUID"] != null)
            {
                string strUserGUID = Session["User_GUID"].ToString();

                string strIndGUID = "";
                string strIndName = "";

                //Initialize Connection String
                cns = DAL360.Common.getConnection(HttpContext.Current.Session["Server"].ToString(), HttpContext.Current.Session["Database"].ToString());

                DAL360.std_UserRepositoryArtifacts.std_UserRepository userRep = new DAL360.std_UserRepositoryArtifacts.std_UserRepository(cns);
                std_User user = userRep.Getstd_UserByusr_GUID(new Guid(strUserGUID));


                DAL360.std_IndividualRepositoryArtifacts.std_IndividualRepository indRep = new DAL360.std_IndividualRepositoryArtifacts.std_IndividualRepository(cns);
                std_Individual ind = indRep.Getstd_IndividualByind_GUID(new Guid(user.usr_ind_GUID.ToString()));

                if (ind != null)
                {
                    strIndGUID = ind.ind_GUID.ToString(); 

                    strIndName = ind.ind_Prefix + " " + ind.ind_FirstName + " " + ind.ind_MiddleName + " " + ind.ind_LastName;

                    DAL360.std_IndividualAddressRepositoryArtifacts.std_IndividualAddressRepository iadRep = new DAL360.std_IndividualAddressRepositoryArtifacts.std_IndividualAddressRepository(cns);
                    List<std_IndividualAddress> iadList = iadRep.GetAllFromstd_IndividualAddressByIndGUID(ind.ind_GUID);

                    if (iadList != null && iadList.Count > 0)
                    {
                        std_IndividualAddress iad = iadList[0];
                        strIndName += " (" + iad.iad_City + ", " + iad.iad_State + ")";
                    }
                }


                strReturn = strIndGUID + ";" + strIndName;

            }//end if statement


            return strReturn;

        }

And this method is in the code behind page of frmHome.aspx page. And I get the error when i try to open the page frmHome.aspx

Share edited Aug 23, 2011 at 20:03 Sampson 269k76 gold badges545 silver badges568 bronze badges asked Apr 26, 2010 at 7:23 Mohammad NadeemMohammad Nadeem 9,39214 gold badges59 silver badges83 bronze badges 3
  • How do you call this function?, the argument res is not being passed correctly (or doesn't contains a value property), also, you will get an invalid left-hand side in assignment error on the two assignments you have inside the if... – Christian C. Salvadó Commented Apr 26, 2010 at 7:27
  • The call to the method is made like this... NewProject.Home.frmHome.getOwnerInfo(loadUser_InfoCallBack) – Mohammad Nadeem Commented Apr 26, 2010 at 7:29
  • This call is made in the same js file – Mohammad Nadeem Commented Apr 26, 2010 at 7:37
Add a ment  | 

1 Answer 1

Reset to default 3

The most probable reason will be that there won't be any element res. So taking res.value will return null, and split is expecting a string.

发布评论

评论列表(0)

  1. 暂无评论