<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = HiddenField1.Value + TextBox1.Text + aaa.InnerHtml;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
function aa() {
document.getElementById("HiddenField1").value="a";
document.getElementById("TextBox1").value="b";
document.getElementById("aaa").innerHTML="c";
}
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="Hidden1" type="hidden" />
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div id="aaa" runat="server"></div>
<br />
<input id="Button1" type="button" value="button" onclick="aa()" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = HiddenField1.Value + TextBox1.Text + aaa.InnerHtml;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
// <!CDATA[
function aa() {
document.getElementById("HiddenField1").value="a";
document.getElementById("TextBox1").value="b";
document.getElementById("aaa").innerHTML="c";
}
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="Hidden1" type="hidden" />
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div id="aaa" runat="server"></div>
<br />
<input id="Button1" type="button" value="button" onclick="aa()" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
</form>
</body>
</html>
这样的使用方法在控件中非常常用,AjaxControlToolkit的基类ExtenderControlBase也使用了这样了方法,其提供了ClientState属性可以获取隐藏域的值.方便了前台和后台的交互