*.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>
中调用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>
<asp:HiddenField ID="HiddenField1" runat="server" />这个...
客户端的value是小写的
因为你使用了母版页
页面解析时,控件ID已经变掉了,你可以在页面加载完成后,查看页面源码时看到
使用控件ID.ClientID是比较稳妥的方法Page.RegisterStartupScript("del","document.getElementById(""+HiddenField1.ClientID+"").Value = '';");
ClientID 通过将子控件的父控件的 UniqueID 值与控件的 ID 值连接生成,各个部分之间以下划线 _ 连接
在子页面里,本页面的服务器控件都被放在了
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">。。</asp:Content>中,
其ID的属性名前都要加上ctl00_ContentPlaceHolder1_,比如ctl00_ContentPlaceHolder1_TextBox1
ClientScript.RegisterStartupScript(this.GetType(), "myconfirm", "document.getElementById('"+ HiddenField1.ClientID+"').Value = confirm('初始化数据'); ");
还是不能弹出confirm按钮啊,但是不提示错啦,这又是哪里出错啦