*.aspx.cs
中调用Page.RegisterStartupScript("del","document.getElementById("Hidden1").Value = confirm('初始化数据')");
老是错误,无法取到hidden1
*.aspx中
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"  AutoEventWireup="true" CodeFile="main.aspx.cs" Inherits="main" Title="无标题页" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
<script runat="server">  
  </script><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
     .style3
        {
            width: 220px;
            height: 472px;
            text-align: left;
            background-color: #FFFFFF;
        }
    .style6
    {
        width: 99%;
    }
        .style7
    {
        height: 23px;
            width: 220px;
     }
        .style9
    {
        height: 23px;
            width: 1000px;
     }
     
      .style8
     {
       width:220px;
     }
        </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    
 <table class="style6">
   <tr>
              <td> 
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    <br />
                    <br />
                    <br />
                    <br />
                    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
                    <br />
                </td>
                
                <td> </table>
    
</asp:Content>

解决方案 »

  1.   

    ","document.getElementById("Hidden1").
    <asp:HiddenField ID="HiddenField1" runat="server" />这个...
      

  2.   

    Page.RegisterStartupScript("del","document.getElementById(""+HiddenField1.ClientID+"").Value = '';");
      

  3.   

    本帖最后由 net_lover 于 2010-08-12 20:21:37 编辑
      

  4.   

    很奇怪你的写法,不说你这样写是不是能得到;HiddenField本来就是前台和后台都可以直接调用的,你为啥要在后台再注册脚本?
      

  5.   

    js调用服务器控件,一定要用ClientID属性,
    客户端的value是小写的
      

  6.   

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="main.aspx.cs" Inherits="main" Title="无标题页" %>
    因为你使用了母版页
    页面解析时,控件ID已经变掉了,你可以在页面加载完成后,查看页面源码时看到
    使用控件ID.ClientID是比较稳妥的方法Page.RegisterStartupScript("del","document.getElementById(""+HiddenField1.ClientID+"").Value = '';");
      

  7.   

    ClientID 表示由服务器端生成的客户端控件的ID,   经常用于在客户端脚本中访问服务器控件所呈现的 HTML 元素。一般情况下与服务器端的 ID 相同,有时,不能为控件生成唯一的名称,
    ClientID 通过将子控件的父控件的 UniqueID 值与控件的 ID 值连接生成,各个部分之间以下划线 _ 连接
    在子页面里,本页面的服务器控件都被放在了
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">。。</asp:Content>中,
    其ID的属性名前都要加上ctl00_ContentPlaceHolder1_,比如ctl00_ContentPlaceHolder1_TextBox1
      

  8.   

    page.RegisterStartupScript()提示版本老啦
    ClientScript.RegisterStartupScript(this.GetType(), "myconfirm", "document.getElementById('"+ HiddenField1.ClientID+"').Value = confirm('初始化数据'); ");
    还是不能弹出confirm按钮啊,但是不提示错啦,这又是哪里出错啦
      

  9.   

    是的,页面套用母版页时候,原页面的控件ID输出到客户端已经变了,所以要用 HiddenField1.ClientID才行
      

  10.   

    你套用了母版以后生成的html不一样了,你自己好好看的!!正确应该是这样的中调用Page.RegisterStartupScript("del","document.getElementById("ctl00_ContentPlaceHolder1_Hidden1").Value = confirm('初始化数据')");
      

  11.   

    用ClientID属性,要不然获取不到值