Page redirection without validation [Resolved]

Posted by Rasagna under ASP.NET on 12/29/2015 | Points: 10 | Views : 981 | Status : [Member] | Replies : 5
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: Jitendrasoft09 on: 12/31/2015 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi,

This is the one of the drawback of asp.net which is roundtrip the entire page click event request on server. But It has the solution for as given below-

Just mentioned in your specified button-
EnableClientScript="False"


Otherwise, enable false in your validations control in button click like as given below-
requiredFileldValidator1.Enable = false;


Refer below link-
http://stackoverflow.com/questions/15827578/enable-disable-required-field-validator-from-cs-page

Jitendra Kumar
If my post helps you, plz mark as an answer.

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