我爱Aspx >> Asp.Net >> ASP.NET 2.0服务器控件与form runat=server标记}
5,百害而无一益?
有时候,页面上需要放置多个form表单(虽然只放置一个<form runat=server></form>的表单也能实现),将表单控件放在<form runat=server></form>标记之外,将非常方便使用,这在以前的asp页面中很常见,现在在aspx中也可义实现。下面的页面,既利用了服务器控件的方便性,也逃脱出了类型“TextBox”的控件“TextBox1”必须放在具有 runat=server 的窗体标记内的限制。例如:
<%@ 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 Button1_Click(object sender, EventArgs e)
{
Response.Write("<li>TextBox1.Text = " + TextBox1.Text);
Response.Write("<li>Request.Params = " + Request.Params[TextBox1.UniqueID]);
}
protected void Page_Load(object sender, EventArgs e)
{
KeyWords.Text = "yaosansi's Blog";
Response.Write("<li>TextBox1.Text = " + TextBox1.Text);
Response.Write("<li>Request.Params = " + Request.Params[TextBox1.UniqueID]);
if (!IsPostBack)
{
TextBox1.Text = "yaosansi's Blog";
}
}
public override void VerifyRenderingInServerForm(Control control)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>VerifyRenderingInServerForm</title>
</head>
<body>
<form method="post" action="SearchDoc.aspx">
关键字:<asp:TextBox ID="KeyWords" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="搜索" />
</form>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" Width="600px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="提交" />
</form>
</body>
</html>
在SearchDoc.aspx页面,使用Request.Form即可获得输入的关键字。
Ҷƪл˵?
使用 C# .NET 写入事件日志[04-21]
ASP.NET 2.0中Page事件的执行顺序[04-21]
ASP.NET Atlas 強力支援您期待已..[04-21]
在ASP.NET Atlas中调用Web Servi..[04-21]
文件压缩代码(为.Net2.0新增)[04-21]
ASP.NET 2.0+Atlas编写鼠标拖放程..[04-21]
ASP.NET2.0中Gridview中数据操作..[04-21]
ASP.NET 2.0中使用multiview控件[04-21]
ASP.NET 2.0中实现跨页面提交[04-21]
ASP.NET 2.0的页面缓存功能介绍[04-21]
使用 C# .NET 写入事件日志[04-21]
我的可爱的小外甥们小侄子们[04-21]
一个高中毕业生关于互联网创业的..[04-21]
BSP 模式的一些思考和结论[04-21]
RSS2.0中文规范详解及示例[04-21]
网易部落的rss弱智错误[04-21]
ASP.NET 2.0中Page事件的执行顺序[04-21]
雅虎搜虫大行动----快来抓毛毛虫..[04-21]
为什么XML文件的分析结果出现乱码..[04-21]
Google(谷歌)中国总部探密[来自..[04-21]