Link to home
Start Free TrialLog in
Avatar of dwoolley3
dwoolley3Flag for United States of America

asked on

How can I return to a page after doing a Response.Redirect and have the exact page previously?

In my ASP.NET page, I have a textbox and a Submit button and a Required Field Validator on the textbox. I have the EnableClientScript set to False so that the required field is only validated on the server side, which subsequently displays an error message. When I start the Web page and click submit without entering something in the textbox, an error message displays. Next, when I enter a few characters in the box and press the Submit button, the message disappears and the VB code redirects the page to a blank page (Default.aspx). When I press the back button on the browser, the previous Web page appears with the error message appearing and the characters I entered in the box. I am not wanting to see this error message when I return to the Web page. How can that be cleared out upon returning?

If the EnableClientScript is set to True, there are no issues. The error message appears on the client side (no post back), then I enter some text, the message goes away and I am redirected to the blank page, then I press the back button and I arrive on the previous page with my entry in the textbox and no error message.

I have simplified my real-world problem to this simple example, but I am wanting to have server side error messages appear, be fixed, then redirect to another page upon submission, then return to the clean page with the proper entry(s) without erroneous error messages that occurred two pages (postbacks) back.

To describe my real-world scenario one step further, I also have a drop-down list that is validated. When the wrong entry is selected (based on knowledge from a database searched on the server), the server-side displays an error message. When the correct drop-down item is selected and the submit button pressed, the page is redirected to another page. When back button is pressed, the server side error message appears eventhough the screen shows the correct drop-down item is selected (on the page), but viewing the source code of the page shows that the previously incorrect drop-down item is "selected". This is strange to me, but I have a feeling some experts may have some ideas to resolve this issue for me.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ControlsDemo.aspx.vb" Inherits="ControlsDemo" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Submit Information" />
        <br />
        <asp:RequiredFieldValidator 
            ID="RequiredFieldValidator1" 
            runat="server" 
            ControlToValidate="TextBox1" 
            ErrorMessage="You must enter something" 
            EnableClientScript="False">
        </asp:RequiredFieldValidator>
   
    </div>
    </form>
</body>
</html>



Partial Class ControlsDemo
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Page.IsValid Then
            Response.Redirect("Default.aspx")
        End If
    End Sub
End Class

Open in new window

Avatar of Mahone7
Mahone7
Flag of Qatar image

You Can use a javascript

<form>
<input type="button" value="Back to Previous Page"
onClick="javascript: history.go(-1)">
</form>
maybe its help you
Avatar of dwoolley3

ASKER

Thanks, but the Response.Redirect places the user on another Web site and the user will probably press the Back button on their browser to come back to my Web tool. I want the Web Tool to then display the same information as before but without any of the error messages previously displayed (since the data was fine when the user pressed the Submit button).
This question is still open, after a month of no responses. Does anyone know how to clear error messages that appeared on the screen prior to being redirected to a new page? I want to be able to go back to this prior page (using the back button) and not see those error messages (either from a server-side Validator or from a label set at the server). Does anyone need any further information from me?
ASKER CERTIFIED SOLUTION
Avatar of dwoolley3
dwoolley3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial