0

I have a form with textboxes which on the first save a submit button becomes visible and when clicked it redirects to a payment page by PostBackURL. The Save creates a Session string which the payment page displays in a Label of the input details. The Sumbit.Visible forces me to save first.

When I click "go Back" by a previous-page link to edit the details, my textboxes have retained the inputs and I can make changes. When I reSave and then click submit, all is well and the Session string is displayed in the next page upon redirecting. If I click Submit without saving, I get a MessageBox popup asking "Save changes?" "Yes" "No". When I click "No", all is well again and the page is redirected with the previous saved Session string. But when I click "Yes", the page is redirected when I don't want it to. I want it to stay on the form page after clicking "Yes" so that I can Save changes and then reSubmit. I've tried Page.PostBcakURL="" in code but this doesn't work if "No" redirects (by PostBackURL). It can work if I use it a button that doesn't redirect.

protected void SubmitPayButton_Click(object sender, EventArgs e)
{
    DialogResult result = MessageBox.Show("Save changes?", "Question",  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

        if (result == DialogResult.Yes)
        {
            //result = DialogResult.None;         
            //SubmitPayButton.Visible = false;                
            //SaveButton.CausesValidation = true;
            //SaveButton.PerformClick();                
            //SubmitPayButton.PostBackUrl = "";

        //None of these work

        }
        if (result == DialogResult.No)
        {                
            processStr();//This works                
        }
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
matt2605
  • 216
  • 1
  • 3
  • 18
  • possible duplicate of [how to show alert box after successful insert using C#](http://stackoverflow.com/questions/16370465/how-to-show-alert-box-after-successful-insert-using-c-sharp) – abatishchev Jan 29 '15 at 22:44
  • I don't think you can use `MessageBox` this way. This code is running on the server - who will be there to click "Yes"? – vesan Jan 29 '15 at 22:44
  • hi abatishchev: the link gives two redirect page links to 'Yes" and 'No'. I want 'Yes' to cancel Page.PostBackURL somehow or stop on the same page. – matt2605 Jan 29 '15 at 22:58
  • sorry vesan, I didn't understand. – matt2605 Jan 29 '15 at 22:59

1 Answers1

0

You definitely will have to work this client (browser) side, this code looks like windows forms code.

The method that suits you would be the confirm method, see it in action here: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_confirm2

(1) But the postback and going back is another issue, maybe you should take a look on saving it with other methods like ajax (you can post the form asynchronous so the browser doesn't know about you call and when clicking back it will behave like nothing happened). (2) Another solution is the one explained here - http://forums.asp.net/t/1304752.aspx - setting no cache for your page so on each back button click the page will be reloaded. My choice would be 1, ajax, because of the user experience and application performance.

Adrian P.
  • 31
  • 1
  • 6
  • The AJAX method looks good: http://ajax.net-tutorials.com/controls/updatepanel-control/ - does anyone know how to stop the page.PostBackURL redirect though by a "Yes""No" messagebox? – matt2605 Jan 30 '15 at 00:42
  • This must be your anwer: http://stackoverflow.com/questions/6402222/aborting-an-ajax-request-if-confirmation-dialog-is-cancel – Adrian P. Jan 30 '15 at 00:49
  • That looks pretty good for an AJAX approach. I still want the asp.net MessageBox to stop a page.PostBackURL redirect with a "Yes" click though. Everything else works. – matt2605 Jan 30 '15 at 01:10
  • I forgot to give feedback. I tried the AJAX approach soon after you gave the comment but when I clicked back to return to the form page, all of the inputs were empty, including the string holding the saved inputs. I abandoned this approach because it immediately puts me back a few steps. I may look at it again in time. – matt2605 Feb 06 '15 at 03:18