?
Solved

How to redirect in ASP.NET?

Posted on 2009-07-08
22
Medium Priority
?
375 Views
Last Modified: 2012-05-07


Hello group,

I'm creating a page (using VB.NET) where I need to have a cancel button on page, also, I'm using few RequiredFieldValidator on the page (to validate a form), in the BtnCancel_Click() event I'm redirecting by:

Response.Redirect("index.aspx")


However, as soon as I click cancel button those RequiredFieldValidators print messages on the page and the doesn't redirect user.

Any help is appreciated.

Regards,
ak

Response.Redirect("index.aspx")

Open in new window

0
Comment
Question by:akohan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
  • 5
22 Comments
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 1000 total points
ID: 24806776
I think you can set "CausesValidation" to false on your cancel button to stop the required field validators
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24807157
hi akohan,

                Make " CausesValidationproperty" property  of cancel button to false



CausesValidation="FALSE"

and under CancelButton_Click you have to write

Response.Redirect("index.aspx");

then it will redirect to the user.
0
 

Author Comment

by:akohan
ID: 24807540

Thanks to all but  RequiredFieldValidators  has no such a property! I went thru its properties but didn't find it

Any idea?

0
How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24807570
on btnCancel, it tells it not to run through the validators
0
 

Author Comment

by:akohan
ID: 24807573

Ok my bad I found it. As you said I found on Cancel button but then didn't work.

0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24807582
BtnCancel.CausesValidation = False
0
 

Author Comment

by:akohan
ID: 24807614

Yes, that is what I did but still it doesn't let me get back to that page and I get validation messages
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24807712
You're setting the CausesValidation during design time, correct?  It would be too late if you code it during the click event.
0
 

Author Comment

by:akohan
ID: 24807740

Right. I made those validation during make the UI. Now what is the solution?
Does this mean ASP.NET has limitations in this case?

Thanks,
ak
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24807822
Can you post the code you have in BtnCancel.click?

Does you button code declaration look like this:
<asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="False" />
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24807840
hi akohan,

                after "CausesValidationproperty" property  of cancel button to false and

under CancelButton_Click event  writing Response.Redirect("index.aspx");

Now your code is working or not?
0
 

Author Comment

by:akohan
ID: 24808413

Tapanpattanaik,

That is what I have done but not working yet.

0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24808449
Can you post some code?
Can you put a break on your response.redirect("index.aspx") line and step through the code?
Does it ever hit that line?

0
 

Author Comment

by:akohan
ID: 24808580


Sure. here

    Protected Sub BtnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
 
        'BtnCancel.CausesValidation = False
 
        Response.Redirect("index.aspx")
 
 
    End Sub
 
 
//Here the html file
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Order.aspx.vb" Inherits="Order" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ICDC Corporate - Office Supplies Order</title>
</head>
<body>
 
 
    <form id="OrderForm" runat="server">
 
 
  <div style="padding-top:10%; padding-left:18%;">
 
  <div style="padding-top:2%; padding-right:10%; padding-left:5%; width:60%; height:50%; border:5px coral groove;" />
 
    <div style="padding-top:5%; padding-left:2%;">
       <asp:Label ID="lblFullName" runat="server" Text="Full Name: "></asp:Label>
       &nbsp;&nbsp;&nbsp;&nbsp;
       <asp:TextBox ID="txtFullName" runat="server" Width="291px" BorderStyle="Outset" 
            MaxLength="100"></asp:TextBox>
        <asp:RequiredFieldValidator ID="rfvFullName" runat="server" 
            ControlToValidate="txtFullName" ErrorMessage="Your Name is Required" 
            Font-Size="9px"></asp:RequiredFieldValidator>
    </div>
    <div style="padding-top:2%; padding-left:2%;">                  
      <asp:Label ID="Label1" runat="server" Text="Deptarment: "></asp:Label>
      &nbsp;&nbsp;
      <asp:DropDownList ID="ddDept" runat="server">
          <asp:ListItem Value="-1">Choose a Department</asp:ListItem>
        </asp:DropDownList>
    </div>
 
    <!-- Details -->
    <div style="padding-top:2%; padding-left:2%;">
    <asp:Label ID="lblProductSku" runat="server" Text="Product SKU: "></asp:Label>
    <asp:TextBox ID="txtProduct" runat="server" Width="215px" BorderStyle="Outset" 
            MaxLength="10"></asp:TextBox>
    <asp:LinkButton ID="lbLookUpLinkButton" runat="server" Font-Size="Smaller"> Lookup Item </asp:LinkButton>
        <asp:RequiredFieldValidator ID="rfvProductNumber" runat="server" 
            ControlToValidate="txtProduct" 
            ErrorMessage="&amp;nbsp;&amp;nbsp;&amp;nbsp; Product No. is Required" 
            Font-Size="9px"></asp:RequiredFieldValidator>
    </div>
    
    <div style="padding-top:2%; padding-left:2%;">
    <asp:Label ID="lblProductDescription" runat="server" Text="Description: "></asp:Label>
    &nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtProductDescription" runat="server" Width="291px" 
            BorderStyle="Outset" MaxLength="50"></asp:TextBox>
        <asp:RequiredFieldValidator ID="rfvDescription" runat="server" 
            ControlToValidate="txtProductDescription" 
            ErrorMessage="Product Description is Missing" Font-Size="9px"></asp:RequiredFieldValidator>
    </div>
    
    <div style="padding-top:2%; padding-left:2%;">
    <asp:Label ID="Label2" runat="server" Text="Qty: "></asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtQty" runat="server" Width="55px" BorderStyle="Outset" 
            MaxLength="3"></asp:TextBox>
 
        <asp:RequiredFieldValidator ID="rfvQty" runat="server" 
            ControlToValidate="txtQty" ErrorMessage="Invalid Number" Font-Size="9px"></asp:RequiredFieldValidator>
 
    </div>
    
    <div align="right" 
          style="padding-top:7%; padding-right:1%; padding-bottom:2%; width: 665px;">
        <asp:Button  ID="BtnCancel" runat="server" Text="Cancel"  />
        <asp:Button  ID="BtnSubmit" runat="server" Text="Submit Order" />
    </div>
            
 
    </div >
    
    
    
    </form>
        
    
    
</body>
</html>

Open in new window

0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24808589
please post your code.

Thanks.
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24809223
I don't see where you have set the CausesValidation property of BtnCancel to False

should be like this:
<asp:Button  ID="BtnCancel" runat="server" Text="Cancel"  CausesValidation="False" />
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24810825
hi akohan

               Check these code and  post your comment.

Thanks
    Protected Sub BtnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
  
        Response.Redirect("index.aspx")
 
 
    End Sub
 
--------------------------------------------------
 
//Here the html file
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Order.aspx.vb" Inherits="Order" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ICDC Corporate - Office Supplies Order</title>
</head>
<body>
 
 
    <form id="OrderForm" runat="server">
 
 
  <div style="padding-top:10%; padding-left:18%;">
 
  <div style="padding-top:2%; padding-right:10%; padding-left:5%; width:60%; height:50%; border:5px coral groove;" />
 
    <div style="padding-top:5%; padding-left:2%;">
       <asp:Label ID="lblFullName" runat="server" Text="Full Name: "></asp:Label>
           
       <asp:TextBox ID="txtFullName" runat="server" Width="291px" BorderStyle="Outset" 
            MaxLength="100"></asp:TextBox>
        <asp:RequiredFieldValidator ID="rfvFullName" runat="server" 
            ControlToValidate="txtFullName" ErrorMessage="Your Name is Required" 
            Font-Size="9px"></asp:RequiredFieldValidator>
    </div>
    <div style="padding-top:2%; padding-left:2%;">                  
      <asp:Label ID="Label1" runat="server" Text="Deptarment: "></asp:Label>
        
      <asp:DropDownList ID="ddDept" runat="server">
          <asp:ListItem Value="-1">Choose a Department</asp:ListItem>
        </asp:DropDownList>
    </div>
 
    <!-- Details -->
    <div style="padding-top:2%; padding-left:2%;">
    <asp:Label ID="lblProductSku" runat="server" Text="Product SKU: "></asp:Label>
    <asp:TextBox ID="txtProduct" runat="server" Width="215px" BorderStyle="Outset" 
            MaxLength="10"></asp:TextBox>
    <asp:LinkButton ID="lbLookUpLinkButton" runat="server" Font-Size="Smaller"> Lookup Item </asp:LinkButton>
        <asp:RequiredFieldValidator ID="rfvProductNumber" runat="server" 
            ControlToValidate="txtProduct" 
            ErrorMessage="&amp;nbsp;&amp;nbsp;&amp;nbsp; Product No. is Required" 
            Font-Size="9px"></asp:RequiredFieldValidator>
    </div>
    
    <div style="padding-top:2%; padding-left:2%;">
    <asp:Label ID="lblProductDescription" runat="server" Text="Description: "></asp:Label>
       
    <asp:TextBox ID="txtProductDescription" runat="server" Width="291px" 
            BorderStyle="Outset" MaxLength="50"></asp:TextBox>
        <asp:RequiredFieldValidator ID="rfvDescription" runat="server" 
            ControlToValidate="txtProductDescription" 
            ErrorMessage="Product Description is Missing" Font-Size="9px"></asp:RequiredFieldValidator>
    </div>
    
    <div style="padding-top:2%; padding-left:2%;">
    <asp:Label ID="Label2" runat="server" Text="Qty: "></asp:Label>
                  
    <asp:TextBox ID="txtQty" runat="server" Width="55px" BorderStyle="Outset" 
            MaxLength="3"></asp:TextBox>
 
        <asp:RequiredFieldValidator ID="rfvQty" runat="server" 
            ControlToValidate="txtQty" ErrorMessage="Invalid Number" Font-Size="9px"></asp:RequiredFieldValidator>
 
    </div>
    
    <div align="right" 
          style="padding-top:7%; padding-right:1%; padding-bottom:2%; width: 665px;">
        <asp:Button  ID="BtnCancel" runat="server" CausesValidation="False" Text="Cancel"  />
        <asp:Button  ID="BtnSubmit" runat="server" Text="Submit Order" />
    </div>
            
 
    </div >
    
    
    
    </form>
        
    
    
</body>
</html>

Open in new window

0
 

Author Comment

by:akohan
ID: 24810902

UnifiedIS,

I had used in VB code not in HTML section as:

BtnCancel.CausesValidation = FALSE

but I guess it was wrong. I will use your code and will get back to you soon.

Thanks,
ak
0
 

Author Comment

by:akohan
ID: 24810905

Tapanpattanaik,

Thanks I will get back to you as soon as I get to my machine.

Thanks,
ak
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24810937
hi akohan,

           modify your code in your source page/html page.

<asp:Button  ID="BtnCancel" runat="server" CausesValidation="False" Text="Cancel"  />



-------------------------------------
and  modify this code in your code behind page.

Protected Sub BtnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
 
        Response.Redirect("index.aspx")
 
 
    End Sub


please check my just previous post .


0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 24812860
There's not any reason to do it at run time, you're not ever going to change it.  Just set the property during design time in the BtnCancel properties window.  Let the IDE write the code!

0
 

Author Closing Comment

by:akohan
ID: 31601258

Thank you and all others.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question