<html>
<head>
<script runat="server" language="c#">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<p>页面的Page_Load事件触发,触发时间是:" + DateTime.Now.ToString());
if (HiddenField1.Value == String.Empty)
HiddenField1.Value = "0";
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<p>Button1_Click为改变Hidden的值前事件触发,触发时间是:" + DateTime.Now.ToString());
HiddenField1.Value = (Convert.ToInt32(HiddenField1.Value) + 1).ToString();
Label1.Text = HiddenField1.Value;
}
protected void HiddenField1_ValueChanged(object sender, EventArgs e)
{
Response.Write("<p>HiddenField的 ValueChanged事件触发,触发时间是:" + DateTime.Now.ToString());
}
</script>
</head>
<body>
<form runat="server">
<div> <asp:HiddenField runat="server" OnValueChanged="HiddenField1_ValueChanged" />
</div> <asp:Label runat="server" Text="Label"></asp:Label>
<br /> <asp:Button runat="server" Text="Button" />
</form></body>
</html>
三、用javascript把值传给HiddenField
javascript直接改变控件的值再后台取不到值,存在HiddenField中变相的取值,代码如下:
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function setValue(){
document.getElementById("<%=name.ClientID %>").value="aaaa";
}
</script>
</head>
<body>
<form runat="server">
<div>
<asp:HiddenField runat="server" />
<asp:Button runat="server" Text="Button"
OnClientClick="setValue()" />
</div>
</form>
</body>
</html>
您可能感兴趣的文章: