我在哪里可以使用这个引用尚未构建的字段的Javascript?

时间:2016-06-16 14:56:34

标签: javascript c#

我有一段JavaScript清除了一个标签(好吧,它设置了它的innertext值)。问题是,在我点击一个按钮并且页面回发后,当Javascript启动时标签不存在。所以,我收到一个错误:

  

0x800a138f - JavaScript运行时错误:无法设置属性   未定义或空引用的“innerText”

调试窗口中的代码如下所示:

.
.
<body id="PageBody" bgcolor="lightgrey">

    <script type = "text/javascript">
        /* Stop, Clear and Pause the timer displayed under the pause buttons  */
        var h1 = document.getElementsByTagName('h1')[0],
            start = document.getElementById('start'),
            stop = document.getElementById('stop'),
            clear = document.getElementById('clear'),
            seconds = 0, minutes = 0, hours = 0,
            t;

        function add() {
            seconds++;
            if (seconds >= 60) {
                seconds = 0;
                minutes++;
                if (minutes >= 60) {
                    minutes = 0;
                    hours++;
                }
            }

            document.getElementById('Call_Tab_TabPanelCall_h1').innerText = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds);;
            timer();
        }

        function timer() {
            t = setTimeout(add, 1000);
        }

        function stp() {
            clearTimeout(t);
        }

        function clr() {
            document.getElementById('Call_Tab_TabPanelCall_h1').innerText = "00:00:00";   
            seconds = 0; minutes = 0; hours = 0;   
        }
    </script>

    <form method="post" action="./MedIntakeMain.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="ctl02_HiddenField" id="ctl02_HiddenField" value="" />
<input type="hidden" name="Call_Tab_ClientState" id="Call_Tab_ClientState" value="{&quot;ActiveTabIndex&quot;:0,&quot;TabEnabledState&quot;:[true,true],&quot;TabWasLoadedOnceState&quot;:[true,false]}" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTAT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9+6EJ0UIZPVF/UIBKvfHyb9SmKL3Dwkx2hVH1LYneM/MFZMDBcD4vmecMYoVNoeO//tuqzFa4/aqcXGoPQ/dEanFOqs5wUI2MrEJ7iRKfXKXTdcRirCCh09KXCgEqZL3exJir2rRvM=" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/WebResource.axd?d=pynGkmcFUV13He1Qd6_TZKuxqzo1qNK0jLS5vOjXgYcG0yOhGAUyRMkYR1c88uLjzDmFYO_wTSY6btwoEa6chQ2&amp;t=635803038500000000" type="text/javascript"></script>


<script type="text/javascript">
//<![CDATA[
stp();clr();timer();//]]>
</

它只是停在</,我猜是HTML会在哪里开始?这是功能clr的第一行突出显示。如果我在函数clr中注释掉2行,一切正常。

在前端使用此asp调用这些函数:

<asp:Button ID="CallStart_Btn" runat="server" AccessKey="S" OnClick="CallStart_Btn_Click" Text="S̲tart" Width="112px" OnClientClick="this.disabled=true; stp(); clr(); timer();" UseSubmitBehavior="False" style="margin-left: 0px"/>

然后在代码隐藏中,我有3行代码:

  ScriptManager.RegisterClientScriptBlock(UpdatePanel4, this.GetType(), "stopscript", "stp();", true);
  ScriptManager.RegisterClientScriptBlock(UpdatePanel4, this.GetType(), "clearscript", "clr();", true);
  ScriptManager.RegisterClientScriptBlock(UpdatePanel4, this.GetType(), "timerscript", "timer();", true);

那么,我可以在哪里放置JavaScript,以便在标签存在后它会被称为

2 个答案:

答案 0 :(得分:2)

使用

ScriptManager.RegisterStartupScript

而不是

ScriptManager.RegisterClientScriptBlock

这会将函数调用放在页面底部。

答案 1 :(得分:0)

有几件事在起作用。

您可以在创建标签之前禁用/隐藏按钮(假设某些用户操作导致标签出现,也可能导致按钮启用/显示)。

您可以为每个函数添加一个检查以确保元素存在。类似的东西:

function clr() {
    var label = document.getElementById('Call_Tab_TabPanelCall_h1');
    if(label){
        label.innerText = "00:00:00";   
    }
    seconds = 0; minutes = 0; hours = 0;   
}