如何接收内容页控件的值
有一母版页: hi.master
有一内容页: profile.aspx
hi.master代码(部分):
<div>
<asp:contentplaceholder id="show" runat="server">
</asp:contentplaceholder>
</div>
profile.aspx代码:
<%@ Page Language="C#" MasterPageFile="~/hi.master" AutoEventWireup="true" CodeFile="profile.aspx.cs" Inherits="pro" Title="资料" %>
<asp:Content ID="profile" ContentPlaceHolderID="show" Runat="Server">
<form id="form1" runat="server">
<div>
<table style="width: 478px; height: 96px;">
<tr>
<td colspan="2" style="height: 33px; text-align: center">
<h1>资料</h1></td>
</tr>
<tr>
<td style="width: 88px; height: 18px;">
E-Mail:</td>
<td style="width: 410px; height: 18px;">
<asp:TextBox ID="email" runat="server" MaxLength="50"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="email"
ErrorMessage="E-Mail不能为空!" Display="Dynamic"></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="email"
Display="Dynamic" ErrorMessage="RegularExpressionValidator" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">请输入合法有效的E-Mail地址!</asp:RegularExpressionValidator></td>
</tr>
<tr>
<td style="width:478px; height: 18px; text-align: center;" colspan=2>
<asp:Button ID="profileM" runat="server" OnClick="Button1_Click" Text="保存" /></td>
</tr>
</table>
</div>
</form>
</asp:Content>
如何接收控件ID为email的值呢,刚开始我以为就直接request.form[""]就可以了,但试了一直不行。
其实仔细想一想,这样不行也是理所当然的。
正确接收值的做法是这样的:
TextBox myemail = (TextBox)this.Page.Master.FindControl("show").FindControl("email");
string email = myemail.Text;