我把
<SCRIPT LANGUAGE='JavaScript'>
var a =  document.all("Label1").innerText;
alert("a"); 
</script>
直接写到ascx页面html中
然后替换各种
document.all("Label1").value;
document.getElementById(' <%= Label1.ClientID %>').value
document.getElementById(' <%= Label1.ClientID %>').innerText
也都是提示页面错误
获取不到Label1的值

解决方案 »

  1.   

    document.getElementById("Label1").innerHTML
      

  2.   

    <SCRIPT LANGUAGE='JavaScript'> 
    var a = document.getElementById("Label1").innerHTML;
    alert("a");
    </script>
    换上这句运行页面也是提示页面有错误。
      

  3.   

    用RegisterClientScriptBlockClientScript.RegisterClientScriptBlock(this.GetType(), string.Format("alert(document.getElementById('{0}').innerText)", Label1.ClientID), "", true); 
      

  4.   

    服务器控件label到了页面之后,被解析成span标签了。用innerHTML应该可以获取到值的。能把你的全代码贴出来么?
      

  5.   

    服务器控件lable里的值现在想在脚本里取最好的方法用隐藏字段
    前台页面定义
    <input type="hidden" id="infos" value=<%=lablevalue%>/>
    后台
    protect string lablevalue;
    string lablevalue=this.Label1.Text 
    这样页面里的脚本就能取到了
    document.getElementById("infos").value
    或者是
    document.aspnetForm.infos.value不过这样的话id="infos"必须该为name="infos"
      

  6.   

    this.Page.RegisterClientScriptBlock(this.GetType(), string.Format("alert(document.getElementById('{0}').innerText)", Label2.ClientID),"",true);运行提示重载“RegisterClientScriptBlock”方法未获取“4”参数
      

  7.   

    同上,查看->源文件,看看你的Label1被编译成什么了,有可能是ID变了。
      

  8.   

        public class ViewDetail : UserControl
        {
            protected Label Label1;
            protected Label Label2;
            protected Label Label3;
            protected Label Label4;
            private void ShowDetail(string id)
               {
                   string[] str = new string[] { "id=" + id };
                   SqlConnection Conn = SqlConn.Instance().GetConnection();
                    try
                      {
                          SqlDataReader reader = SqlHelper.ExecuteReader(Conn, "usp_getlist", str);
                           while (reader.Read())
                           {
                               this.Label1.Text = reader[0].ToString();
                               this.Label2.Text = reader[1].ToString();
                               this.Label3.Text = reader[2].ToString();
                               this.Label4.Text = reader[3].ToString();
                            }
                             reader.Close();
    this.Page.RegisterStartupScript("","<SCRIPT LANGUAGE='JavaScript'> var a = document.getElementById(' Label1').innerText; alert('a');</script>");
                            catch
                                {
                                      throw new ApplicationException("取信息错,请刷新");
                                 }

                            finally
                                {
                                     if (Conn != null)
                                {
                                     Conn.Close();
                                     Conn.Dispose();
                                 }
                      }
             } 
      

  9.   

    是ClientScript
    ClientScript.RegisterClientScriptBlock
      

  10.   

    源文件 <table cellSpacing="0" cellPadding="0" width="90%" align="center" border="0">
    <tr>
    <td style="FONT-WEIGHT: bold; FONT-SIZE: 18px; FONT-FAMILY: 黑体; HEIGHT: 18px" width="32%"
    height="18">姓名:</td>
    <td style="HEIGHT: 18px">&nbsp;
    <asp:label id="Label1" runat="server" Font-Names="宋体" Font-Bold="True" Font-Size="18px"></asp:label></td>
    </tr>
    <tr>
    <td height="20">性别:
    </td>
    <td>&nbsp;
    <asp:label id="Label2" runat="server"></asp:label></td>
    </tr>
    发布后源文件
    <table cellSpacing="0" cellPadding="0" width="90%" align="center" border="0">
    <tr>
    <td style="FONT-WEIGHT: bold; FONT-SIZE: 18px; FONT-FAMILY: 黑体; HEIGHT: 18px" width="32%"
    height="18">姓名:</td>
    <td style="HEIGHT: 18px">&nbsp;
    <span id="ViewDetail1_Label1" style="color:White;background-color:Blue;font-family:宋体;font-size:18px;font-weight:bold;">张建民            </span></td>
    </tr>
    <tr>
    <td height="20">性别:
    </td>
    <td>&nbsp;
    <span id="ViewDetail1_Label2">男        </span></td>
    </tr>
      

  11.   

    <span id="ViewDetail1_Label1" style="color:White;background-color:Blue;font-family:宋体;font-size:18px;font-weight:bold;">张建民</span>
    看,原来的label已经变成了span。而且,id也因为你做的是ascx页面控件,所以,id产生了变化。获取ViewDetail1_Label1就能获取到label了
      

  12.   

    我用的是.NET Framework 1.1
    没有Page.ClientScript 属性
      

  13.   

    14楼不是告诉你了么,id变成"ViewDetail1_Label1"了,
    <SCRIPT LANGUAGE='JavaScript'> 
    var a = document.getElementById("ViewDetail1_Label1").innerHTML; 
    alert("a"); 
    </script>
      

  14.   

    呵呵  谢谢啊 
    谢谢各位大虾啊
    实现了!就是14楼说的问题
    不过document.getElementById("ViewDetail1_Label1").innerHTML;不行
    要用document.getElementById("ViewDetail1_Label1").innerText;