Great question that I'm facing right now. I don't know the answer either, I would imagine one would modify Request.Form
data to remove the event, though I'm not sure how to do this cleanly.
As a workaround, I use a guard flag in Context.Items
, which is preserved as well.
protected void rbThemes_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsSecondPass()) return;
Server.Transfer(Request.FilePath, true);
}
private bool IsSecondPass()
{
const string key = "SECOND_PASS_GUARD";
if (Context.Items[key] == null)
{
Context.Items[key] = new object();
return false;
}
else
{
Context.Items.Remove(key);
return true;
}
}
I wouldn't recommend this, but it works. (Method name is also very poorly chosen as it side-effects.)
There's also a shorter way:
protected void rbThemes_SelectedIndexChanged(object sender, EventArgs e)
{
if (PreviousPage != null) return;
Server.Transfer(Request.FilePath, true);
}
Beware that it doesn't have any undesired effects if you do other kinds of cross-page postings (though I don't know why or how you would cross-post a SelectedIndexChanged
event from another page). Still not recommended.
Note: If you're coding a master page, you'll need to reference PreviousPage
from the Page
property on the master page class (Page.PreviousPage
).