前台HTML代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
就是隐藏字段,常被用与表单中,传送一个隐藏的值!下面演示的是给隐藏字段赋值并显示出来!<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="按一盘看" /></div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
就是隐藏字段,常被用与表单中,传送一个隐藏的值!下面演示的是给隐藏字段赋值并显示出来!<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="按一盘看" /></div>
</form>
</body>
</html>
后台C#代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (HiddenField1.Value == string.Empty)//判断如果现在隐藏字段的值为空
HiddenField1.Value = "代表川哥向你问好!";
else
HiddenField1.Value = "这是第二次按了";
Response.Write(HiddenField1.Value.ToString());//在屏幕上打印出隐藏字段的值
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (HiddenField1.Value == string.Empty)//判断如果现在隐藏字段的值为空
HiddenField1.Value = "代表川哥向你问好!";
else
HiddenField1.Value = "这是第二次按了";
Response.Write(HiddenField1.Value.ToString());//在屏幕上打印出隐藏字段的值
}
}