本文介绍了JavaScript运行时错误:无法获取未定义或空引用的属性“值”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个javascript代码来显示特定日历的下一个日期

I wrote a javascript code to display the next date of a specific calendar

我的功能

function verificaDataReferencia(mensagem)
            {
                if(document.getElementById("txtDataReferencia1Hidden") == null || document.getElementById("txtDataReferencia2Hidden") == null || document.getElementById("ddlDataPub") == null || document.getElementById("txtDataRefInfo") == null)

                var objtxtDataReferencia1Hidden = document.getElementById("txtDataReferencia1Hidden").value;

                var objtxtDataReferencia2Hidden = document.getElementById("txtDataReferencia2Hidden").value;

                > Breakpoint var objtxtDataArquivo = document.getElementById("ddlDataPub").value;

                var mensagem = document.getElementById("txtDataRefInfo").value;
                if((objtxtDataReferencia1Hidden == objtxtDataArquivo) || (objtxtDataReferencia2Hidden == objtxtDataArquivo))
                {
                    var x = alert(mensagem);
                    return x;
                }
            }

Html

<asp:TextBox style="Z-INDEX: 112; POSITION: absolute; TOP: 9px; LEFT: 572px" id="txtDataReferencia1Hidden"
                                            runat="server" CssClass="inputLabel" Width="15" Height="15px"></asp:TextBox>
                                        <asp:TextBox style="Z-INDEX: 113; POSITION: absolute; TOP: 9px; LEFT: 606px" id="txtDataReferencia2Hidden"
                                            runat="server" CssClass="inputLabel" Width="14" Height="14px"></asp:TextBox>

问题是该页面在chrome中运行良好但是当我在IE中运行我的应用程序时它会抛出错误

the problem is that the page is running well in chrome but when i run my application in IE it throw an error

请帮我解决这个问题。

private void Page_Load(object sender, System.EventArgs e)
        {

            if(! IsPostBack)
            {
                txtNomePortugues.SetFocus();
                BO.Pasta pasta = new BO.Pasta(CodPasta);
                if (CodigoArquivo == 0 && !IsJustificativa && pasta.EnviaEmail)
                    btnGravar.Attributes.Add("onclick", "verificaDataReferencia(); confirmaEnvioEmail('" + GetString("Mensagem_Confirmacao_Alerta_Arquivos") + "');");
                else
                    btnGravar.Attributes.Add("onclick", "verificaDataReferencia();");


推荐答案

您需要将控件上的ClientIDMode属性设置为:

You need to set the ClientIDMode attribute on the control to:

ClientIDMode="Static"

这适用于.Net 4.0及以上

This works with .Net 4.0 and upwards

这篇关于JavaScript运行时错误:无法获取未定义或空引用的属性“值”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 12:08