简体   繁体   English

未捕获的类型错误:无法读取 null 的属性“值”

[英]Uncaught TypeError: Cannot read property 'value' of null

Hello I am working on an ASP.NET page where I want to view data from database using AJAX您好,我正在处理一个 ASP.NET 页面,我想在其中使用 AJAX 查看数据库中的数据

What I have done is created the following C# method:我所做的是创建了以下 C# 方法:

[System.Web.Services.WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
public static void ViewData(string contNumber, string BookingNo)
{
    if (contNumber != "" && BookingNo != "")
    {
        string container = contNumber;
        string booking = BookingNo;

        db.SelectData(container, booking);
        HttpContext.Current.Response.Write("IN!!"+ booking);
    }
}

I then call this method using AJAX, here the code:然后我使用 AJAX 调用此方法,代码如下:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script

        function View() {

            var container = document.getElementById("#<%=contNoTxtBox.ClientID%>").value;
            var booking = document.getElementById("#<%=bookingNoTxtBox.ClientID%>").value;

          //  var cont = container.value;
         //   var book = booking.value;

            $.ajax(
                {

                    type: "POST",
                    url: "VGMForm.aspx/ViewData",
                    data: '{contNumber: "' + $(container) + '", BookingNo: "' + $(booking) + '"}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json"

                });


        }

From my HTML page I call the function using the following code:在我的 HTML 页面中,我使用以下代码调用该函数:

<input id="Button1" type="button" value="button" onclick="View()" />

However, when I click on the button, I receive the following error:但是,当我单击按钮时,收到以下错误:

Uncaught TypeError: Cannot read property 'value' of null未捕获的类型错误:无法读取 null 的属性“值”

I am unsure as to what is causing this error, what is the cause and how can I resolve it?我不确定导致此错误的原因是什么,原因是什么以及如何解决?

Some of getElementById returns null一些getElementById返回null

  document.getElementById("#<%=contNoTxtBox.ClientID%>")

or或者

  document.getElementById("#<%=bookingNoTxtBox.ClientID%>")

I was able to solve it by removing the .ClientID from the script as the following:我能够通过从脚本中删除 .ClientID 来解决它,如下所示:

var container = document.getElementById("contNoTxtBox").value;
 var booking = document.getElementById("bookingNoTxtBox").value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:无法读取null的属性“值” - Uncaught TypeError: Cannot read property 'value' of null 未捕获的类型错误:无法读取 null 的属性“值” - Uncaught TypeError: Cannot read property 'value' of null 未捕获的TypeError:值更改时无法读取null的属性“值” - Uncaught TypeError: Cannot read property 'value' of null at value change 未捕获(承诺)类型错误:无法读取 null 的属性“值” - Uncaught (in promise) TypeError: Cannot read property 'value' of null JAVASCRIPT-未捕获的TypeError:无法读取null的属性“值” - JAVASCRIPT - Uncaught TypeError: Cannot read property 'value' of null 如何解决“未捕获的TypeError:无法读取null的属性&#39;value&#39;” - How to solved “Uncaught TypeError: Cannot read property 'value' of null” 未捕获的TypeError:无法以离子反应形式读取null的属性“值” - Uncaught TypeError: Cannot read property 'value' of null in ionic reactive form 如何修复未捕获的类型错误:无法读取 null 的属性“值” - how to fix the Uncaught TypeError: Cannot read property 'Value' of null 未捕获的类型错误无法读取 javascript 中 null 的属性(读取“值”) - Uncaught typeerror cannot read property of null (reading 'value') in javascript 未捕获的TypeError:无法使用joomla读取null的属性“值” - Uncaught TypeError: Cannot read property 'value' of null using joomla
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM