2013-03-06 3 views
0
<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> 

Мои Validations работают хорошо, когда я получил эту страницу после Response.RedirectValidations не работает после Server.Transfer в asp.net

Однако после того, как Server.Transfer этой страницы валидация перестают работать и форма делает постбэк на кнопки мыши

код За Pevious Страница:

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); 
       } 
      } 
     } 

Код Позади Landing Page:

protected void btnAdd_Click(object sender, EventArgs e) 
    { 
     try 
     { 


      if (iEmployeeId != 0) 
      { 
       UpdateEmployeeDetails(iEmployeeId); 
       Response.Write("<script> alert('User Updated sucessfully. ');window.location.href='Employee.aspx'; </script> "); 
      } 
      else 
      { 
       InsertEmployeeDetails(); 
       Response.Write("<script> alert('User Added sucessfully. ');window.location.href='Employee.aspx'; </script> "); 
      } 
     } 

ответ

1

Причиной может быть:

As Response.Redirect informs Client(Browser) and then Redirect the page, so validation work is working fine(as validation is done on client side)

whereas Server.Transfer will directly transfer to requested page without informing client, avoiding extra round trip so validation isn't done

Also Since we are not informing client -> web address on the client won't change

+0

Нет ли обходного пути для решения этой проблемы? – vini

+0

Ваша работа не может быть выполнена с помощью Response.Redirect? – vikbehal

+0

Мне нужно перенести многие значения с одной страницы на другую, поэтому – vini

0

Я просто избежать Server.Transfer, так как это происходит очень часто, что некоторые функции просто не работают должным образом, когда этот метод od используется. Единственным преимуществом метода server.transfer является то, что он не требует другого запроса от клиента, который имеет значение только на очень занятых серверах.

Вот что я рекомендую.

  • Использование Response.Redirect() для передачи на другую страницу
  • Используйте Session или Application или печенье для передачи параметров из одной страницы на другую.