Page redirection without validation [Resolved]

Posted by Rasagna under ASP.NET on 12/29/2015 | Points: 10 | Views : 1265 | Status : [Member] | Replies : 4
Hiii,
I need to redirect to a page without validation on pressing cancel button .Even after setting 'CausesValidation ' to 'False' my form is asking for validation.My codes are as below.
.aspx.cs file code
  protected void Cancel_Click(object sender, EventArgs e)
{
Response.Redirect("EmployeeDetails.aspx");
}

.aspx code
<asp:Button ID="Cancel" runat="server" Text="Cancel" CssClass="auto-style26" CausesValidation="False" OnClick="Cancel_Click"  />

why is this happening?




Responses

Posted by: Sheonarayan on: 1/5/2016 [Administrator] HonoraryPlatinum | Points: 50

Up
1
Down

Resolved
The other solution of this problem can be following.

<input type="button" onclick="Redirect()" value="Cancel" />

<script>
function Redirect(){
window.location.href = "EmployeeDetails.aspx";
}
</script>

Instead of redirecting from server side, do it from client side using JavaScript. See the Demo here http://techfunda.com/Examples/Show/436.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Professionaluser on: 12/31/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
refer
https://msdn.microsoft.com/en-us/library/bt244wbb.aspx

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rasagna on: 1/5/2016 [Member] Starter | Points: 25

Up
0
Down
@Jitendrasoft09 it is showing Error As - Validation (ASP.Net): Attribute 'EnableClientScript' is not a valid attribute of element 'Button'.


Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rasagna on: 1/5/2016 [Member] Starter | Points: 25

Up
0
Down
@Sheonarayan Thanks it helped..

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response