I have a button on an ASP.Net page that will call Response.Redirect back to the same page after performing some processing in order to re-display the results of a query. However, for some reason, the page comes up blank. It seems that IsPostBack is returning true after the redirect. Anybody know why this would happen?
The page is a custom page in Community Server. Here is the basic code:
void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string connStr = ConfigurationManager.ConnectionStrings['SiteSqlServer'].ConnectionString; SqlDataAdapter da = new SqlDataAdapter('SELECT * FROM ge_vw_NonResidents', connStr); DataTable tbl = new DataTable(); da.Fill(tbl); da.Dispose(); rptNonResidents.DataSource = tbl; rptNonResidents.DataBind(); } } void btnApprove_Command(object sender, CommandEventArgs e) { // Code removed for testing. Response.Clear(); Response.Redirect('ApproveResidents.aspx', true); Response.End(); }
Sorry, it was an id-10-t error. My event handler wasn’t getting called at all. The page had EnableViewState=’false’. Once I changed that to true it worked.
I also took tvanfosson suggestion. This allows me to display a confirmation message. I can easily check to see if the action has already been taken and safely ignore it. Since I’m likely the only one to ever see this screen, I’m not too concerned with usability.