调用JS用Page.ClientScript.RegisterClientScriptBlock,页面标题不明白楼主的意思,放个变量不就得了

解决方案 »

  1.   

    我后来又改了一下,建了个JS文件
    TIME.JS
    function time()
    {
      function updateTime()
                {
                    var label = document.getElementById(currentTime');                alert(label);\\就是这一行显示谈出值是NULL,                if (label) {
                        var time = (new Date()).localeFormat("T");
                        label.innerHTML = time;
                    }
                }
                updateTime();
                window.setInterval(updateTime, 1000);
    }
    我用this.Page.ClientScript.RegisterClientScriptBlock这个方法注册了这个JS,但是我在前面写的测试用的ALERT弹出值是一个NULL,所以肯定就没有执行找到页面文件中的LABEL ID=CURRENTTIME.请大家帮我解决,谢谢!@
      

  2.   

    所有用到的对象id需要使用
    服务器对象的.ClientID
      

  3.   

    你看一下生成的页面源码,会发现注册的JS是在你的ID对象产生前,所以改变一下JS的位置就可以了。
    搜索一下‘asp.net调用JS’你会得到许多信息。
      

  4.   

    TIME.JS一定要放在id = "currentTime"的控件后面
      

  5.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="time2.aspx.cs" Inherits="time2" %>
    <%@ Register
        Assembly="AjaxControlToolkit"
        Namespace="AjaxControlToolkit"
        TagPrefix="ajaxToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        
        </div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <span id="currentTime" runat="server" style="font-size:xx-large;font-weight:bold;line-height:40px;"/>
                </ContentTemplate>
            </asp:UpdatePanel>
            <script type="text/javascript" language="javascript">
                function updateTime()
                {
                    
                    var label = document.getElementById('currentTime');
                    if (label) {
                        var time = (new Date()).localeFormat("T");
                        label.innerHTML = time;
                    }
                }
                
                updateTime();
                window.setInterval(updateTime, 1000);
            </script>
        </form>
    </body>
    </html>
    这样都不执行了