C# asp.net中server.transfer之后验证不起作用

C# asp.net中server.transfer之后验证不起作用,c#,asp.net,validation,server.transfer,C#,Asp.net,Validation,Server.transfer,当我在响应后进入此页面时,我的验证工作正常。重定向 但是,在服务器.Transfer to this page验证停止工作后,表单会单击按钮进行回发 上一页后面的代码: <td align="left" width="15%" class="body_txt" style="padding-right: 2px; padding-left: 25px;"> <asp:Label ID="lblFirstName" runat="server" Te

当我在响应后进入此页面时,我的验证工作正常。重定向

但是,在服务器.Transfer to this page验证停止工作后,表单会单击按钮进行回发

上一页后面的代码:

   <td align="left" width="15%" class="body_txt" style="padding-right: 2px; padding-left: 25px;">
            <asp:Label ID="lblFirstName" runat="server" Text="First Name:"></asp:Label>
        </td>
        <td width="35%" align="left" style="padding-left: 25px;">
            <asp:TextBox ID="txtFirstName" Width="175px" MaxLength="50" runat="server" CssClass="txt_bx"></asp:TextBox>
            <asp:RegularExpressionValidator ID="RegularExpressionValidatorFirstName" ControlToValidate="txtFirstName"
                SetFocusOnError="true" runat="server" ErrorMessage="*" EnableClientScript="true" ValidationExpression="([a-z]|[A-Z])*"
                ForeColor="Black"></asp:RegularExpressionValidator>
        </td>
        <td width="15%" class="body_txt" align="left" style="padding-right: 2px; padding-left: 25px;">
            <asp:Label ID="lblLastName" runat="server" Text="Last Name:"></asp:Label>
        </td>
        <td width="35%" align="left" style="padding-left: 25px">
            <asp:TextBox ID="txtLastName" Width="175px" MaxLength="50" runat="server" CssClass="txt_bx"></asp:TextBox>
            <asp:RegularExpressionValidator ID="RegularExpressionValidatortxtLastName"  EnableClientScript="true" ControlToValidate="txtLastName"
                SetFocusOnError="true" runat="server" ErrorMessage="*" ValidationExpression="([a-z]|[A-Z])*"
                ForeColor="Black"></asp:RegularExpressionValidator>
        </td>
  protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i < lstEmployee.Rows.Count; i++)
            {
                GridViewRow row = lstEmployee.Rows[i];
                bool isChecked = ((RadioButton)row.FindControl("RowSelector")).Checked;

                if (isChecked)
                {
                    iEmployeeId = Convert.ToInt32(row.Cells[0].Text);
                    hdnEmployeeId.Value = Convert.ToString(iEmployeeId);
                    Server.Transfer("EmployeeMaint.aspx", true);
                }
            }
        }
protectedvoidbtnedit\u单击(对象发送方,事件参数e)
{
尝试
{
对于(int i=0;i
登录页后面的代码:

   <td align="left" width="15%" class="body_txt" style="padding-right: 2px; padding-left: 25px;">
            <asp:Label ID="lblFirstName" runat="server" Text="First Name:"></asp:Label>
        </td>
        <td width="35%" align="left" style="padding-left: 25px;">
            <asp:TextBox ID="txtFirstName" Width="175px" MaxLength="50" runat="server" CssClass="txt_bx"></asp:TextBox>
            <asp:RegularExpressionValidator ID="RegularExpressionValidatorFirstName" ControlToValidate="txtFirstName"
                SetFocusOnError="true" runat="server" ErrorMessage="*" EnableClientScript="true" ValidationExpression="([a-z]|[A-Z])*"
                ForeColor="Black"></asp:RegularExpressionValidator>
        </td>
        <td width="15%" class="body_txt" align="left" style="padding-right: 2px; padding-left: 25px;">
            <asp:Label ID="lblLastName" runat="server" Text="Last Name:"></asp:Label>
        </td>
        <td width="35%" align="left" style="padding-left: 25px">
            <asp:TextBox ID="txtLastName" Width="175px" MaxLength="50" runat="server" CssClass="txt_bx"></asp:TextBox>
            <asp:RegularExpressionValidator ID="RegularExpressionValidatortxtLastName"  EnableClientScript="true" ControlToValidate="txtLastName"
                SetFocusOnError="true" runat="server" ErrorMessage="*" ValidationExpression="([a-z]|[A-Z])*"
                ForeColor="Black"></asp:RegularExpressionValidator>
        </td>
  protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i < lstEmployee.Rows.Count; i++)
            {
                GridViewRow row = lstEmployee.Rows[i];
                bool isChecked = ((RadioButton)row.FindControl("RowSelector")).Checked;

                if (isChecked)
                {
                    iEmployeeId = Convert.ToInt32(row.Cells[0].Text);
                    hdnEmployeeId.Value = Convert.ToString(iEmployeeId);
                    Server.Transfer("EmployeeMaint.aspx", true);
                }
            }
        }
protectedvoidbtnadd\u单击(对象发送者,事件参数e)
{
尝试
{
如果(IEEmployeeId!=0)
{
更新员工详细信息(IEEmployeeId);
Response.Write(“警报('User Updated successfully');window.location.href='Employee.aspx';”;
}
其他的
{
插入员工详细信息();
Response.Write(“警报('User Added successfully');window.location.href='Employee.aspx';”;
}
}
原因可能是:

作为响应。重定向通知客户端(浏览器),然后重定向页面,因此验证工作正常(验证在客户端完成)

而Server.Transfer将在不通知客户端的情况下直接传输到请求的页面,避免了额外的往返,因此不会进行验证


另外,由于我们没有通知客户机->客户机上的网址不会更改,因此我会避免使用server.transfer,因为使用此方法时,经常会出现某些功能无法正常工作的情况。server.transfer方法的唯一优点是不需要客户机发出另一个请求这只会在非常繁忙的服务器上产生影响

以下是我的建议

  • 使用Response.Redirect()传输到另一个页面
  • 使用会话、应用程序或cookie将参数从一个页面传输到另一个页面

我必须将大量值从一个页面传输到另一个页面,这就是为什么不能使用会话对象存储多个值?