I am using:
Response.Redirect(Request.RawUrl);
to force a postback on my web page. However, the path of execution in the code is as if the page were loading for the first time. How do I cause just an ordinary postback?
Any advice is appreciated.
Regards.
EDIT:
This post seems to be attracting a lot of negativity. I got this method from a Stock Overflow post after a Google search for forcing a postback. So the downvoters should probably take out their frustrations on that post instead of mine.
To clear up some of the misapprehensions about my question:
I have an event Button_Click that contains logic in the method body — obviously. However the flow of execution of the code goes like this:
Button_Click –> Page_Load (IsPostBack == true) –> Button_Click body –> execution ends.
So my problem is that none of the logic in the body of Button_Click is showing up on the page because the postback is done before any of the code in the body of Button_Click is executed.
EDIT:
Here is the event:
protected void RedoEdits_Click(Object sender, EventArgs e)
{
// Goes to Page_Load here with IsPostBack == true
string trendsFileLocation = currDir + "\\" + reportDir + "\\" + trendsFile;
string messagesFileLocation = currDir + "\\" + reportDir + "\\" + messagesFile;
if (File.Exists(trendsFileLocation))
{
File.Delete(trendsFileLocation);
}
if (File.Exists(messagesFileLocation))
{
File.Delete(messagesFileLocation);
}
trendsXML.Clear();
editMode = "redo";
}
Code snippet for IsPostBack == true:
if (editMode.Equals("redo"))
{
editMode = "";
ViewReport_Click(null, null);
}
The code snippet never gets exercised because the postback happens first, skips the snippet because editMode != redo, then finishes with the body of RedoEdits_Click which finally sets editMode == redo but since the postback has already happened we don’t get to ViewReport_Click.
And btw, editMode is a session variable so it persists.
I needed the page reload to restore my original, unedited, HTML. The process of editing the table replaced some InnerHTML and I needed to start over to redo the edits. So I just moved the logic necessary for redoing the edits in the code for IsPostBack != true and stayed with Response.Redirect(Request.RawUrl). Works like a charm.