<input type="hidden" id="confirm" runat ="server" value="true"/>
我前台写了这样一个隐藏域,渲染出来他的Id不知道为什么变成了'ctl00_DataList_confirm'但是我用
    var I=document.getElementById('ctl00_DataList_confirm')
   var I=document.getElementById('confirm')
这两个Id都得不到这个控件。这是什么原因?

解决方案 »

  1.   

    runat ="server" 不要就可以了
      

  2.   

    你的隐藏域是放在DataList容器控件中的吧,
    document.getElementById('<%=confirm.ClientID%>');
      

  3.   

    但是我后台需要判断这个隐藏域的value。如果没有了runat那我怎么取得他的value呢?
      

  4.   

    这样还是去不到。我没放在datalist里面。
      

  5.   

    <asp:Content ID="Content1" ContentPlaceHolderID="DataList" Runat="Server">
        <style type="text/css">
            .style1
            {
                height: 267px;
                width: 1000px;
                padding-top:30px;
            }
            .style2
            {
                height: 3px;
            }
            .style4
            {
                width: 405px;
            }
            .style5
            {
                height: 3px;
                width: 405px;
            }
            .style6
            {
                width: 128px;
            }
            .style7
            {
                height: 3px;
                width: 128px;
            }
        </style>
    <div class="style1">
        
        <table style="width:100%;">
                                
            <tr>
                <td class="style5">
                    &nbsp;</td>
                <td class="style7">
    <asp:Label ID="Label4" runat="server">文件名</asp:Label> 
                </td>
                <td class="style2" align="left">
        <asp:TextBox ID="TextBox1" runat="server" Width="177px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style4">
                    &nbsp;</td>
                <td class="style6">
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" 
            Text="文件上传" Height="21px"  />
                </td>
                <td align="left">
    <asp:Label ID="Label1" runat="server"></asp:Label> 
                </td>
            </tr>
        </table>
        <br />
        <br />
     </div><input type="hidden" id="confirm" runat ="server" value="true"/>
    </asp:Content>
      

  6.   


    <asp:Content ID="Content1" ContentPlaceHolderID="DataList" runat="Server">
        <input type="hidden" id="confirm" runat="server" value="true" />    <script type="text/javascript">
            var ss = document.getElementById('<%=confirm.ClientID %>');
            alert(ss.value);
        </script></asp:Content>