Saturday, March 31, 2012

Strange Behavior

Hi All,
I have a webapp page that gathers a bunch of parameters and then saves the parameters into a session variable (as an object). The code then redirects via Response.Redirect() to a new page. The new page then renders a chart based on the values stored in the session variable. On the resulting page I have a button that redirects back to the original page with the form. I'm doing this as follows: Response.Redirect("Frm_KPI.aspx?redo=1");
In the Page_Load() method in "Frm_KPI.aspx.cs" I have the following code:

protectedvoid Page_Load(object sender, System.EventArgs e)

{

//

// Initialize the database connection

//

InitDB();

// Check the query string to see if user wants to reload the form.

if (Quartz_QueryString("redo") =="1")

{

//

// User wants to reload the form from the Session parameter object

//

m_Params = (CKPIParameters)Session["KPI_PARAMS"];

InitJobTypeList(true);

InitJobOwnerList(true);

InitTimingParameters(true);

InitInterval(true);

InitTimeBase(true);

InitNormalizeBy(true);

InitJobPriorityList(m_Params.JobType,true);

InitJobAnalysisMode(m_Params.JobType,true);

InitJobAnalysisHistory(m_Params.JobType,true);

}

else

{

if (!IsPostBack)

{

m_Params.JobType ="SEM";

InitJobTypeList(false);

InitJobOwnerList(false);

InitTimingParameters(false);

InitInterval(false);

InitTimeBase(false);

InitNormalizeBy(false);

InitJobPriorityList(m_Params.JobType,false);

InitJobAnalysisMode(m_Params.JobType,false);

InitJobAnalysisHistory(m_Params.JobType,false);

m_hplStartDate.NavigateUrl ="javascript:;";

m_hplEndDate.NavigateUrl ="javascript:;";

this.m_editStartDate.Text ="01/01/2005";

this.m_editEndDate.Text ="12/31/2005";

//

// Now disable all of the controls except for the job type selector

//

EnableControls(false);

ShowControls(false);

}

}

}

privatestring Quartz_QueryString(string strName)

{

string strReturn ="";

if (Request.QueryString[strName] !=null && Request.QueryString[strName].Length > 0)

{

strReturn = Request.QueryString[strName].ToString();

}

return (strReturn);

}



The problem is that when the new page is redisplayed, all the values are set correctly, but when I attempt to resubmit the page, the line
if (Quartz_QueryString("redo") =="1")

resolves to true even though I'm doing a post via my submit button. Consequently any changes I make to the variables don't stick when the form is ultimately submitted. Any thoughts??
Regards,
Greg.

Possible solution:
I changed the QueryString check to the following:

if (Context.Items["RedoQuery"] !=null && Context.Items["RedoQuery"].ToString().Length > 0)
{
// Reload form from session values
}

This has the desired effect. After the initial Page_Load() the context disappears and the above code block is not called repeatedly.

0 comments:

Post a Comment