我有以下几行JavaScript:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MedIntakeMain.aspx.cs" Inherits="THNDPL_New.MedIntakeMain" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<title>Medical Intake Daily Production Log</title>
</head>
<body id="PageBody" runat="server">
<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('<%=h1.ClientID%>').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('<%=h1.ClientID%>').innerText = "00:00:00";
seconds = 0; minutes = 0; hours = 0;
}
</script>
<form id="form1" runat="server">
<asp:toolkitscriptmanager runat="server"></asp:toolkitscriptmanager>
.
.
etc...
当我将其添加到按钮的OnClick事件时,一切都消失了:
ScriptManager.RegisterStartupScript(UpdatePanel4, this.GetType(), "stopscript", "stp();", true);
ScriptManager.RegisterStartupScript(UpdatePanel4, this.GetType(), "clearscript", "clr();", true);
ScriptManager.RegisterStartupScript(UpdatePanel4, this.GetType(), "timerscript", "timer();", true);
UpdatePanel4确实存在,如下所示:
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:Label ID="h1" runat="server" ForeColor="Black"><time>00:00:00</time></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
如果我查看页面的来源,它会显示我的所有控件(文本框,下拉列表,按钮等等),但它们不会呈现。
为什么会发生这种情况的任何想法?