P
Paul Rogers
I have an existing .NET ( 1.1) application, and I ran Microsoft's FxCop on
it, and it screamed at me about directly using textbox.text values instead
of session values. So, I tried to re-write parts of it using session
variables and got no where.
The (Pseudo) code that doesn't work at all is as follows:
Page_Load( )
{
if ( !IsPostBack )
{
CreateSessionVariables();
LoadSessionVariablesFromDB();
PushSessionVariablesToControls();
}
else
{ PushSessionVariablesToControls(); }
}
TextBox1ON_TextChange( )
{ Session["TextBox1Value"] = TextBox1.Text; }
TextBox2On_TextChange( )
{ Session["TextBox2.Value"] = TextBox2.Text; }
ButtonSaveToDBOnClick()
{ PushSessionVariablesToDB() }
CreateSessionVariables()
{
Session["TextBox1Value"] = "";
Session["TextBox2Value"] = "";
}
LoadSessionVariablesFromDB()
{
string sql = "Select TB1Value, TB2Value from MYDB";
other sql stuff;
SqlDataReader rdr = .........;
if ( rdr.read() )
{
if (!rdr.IsDbNull(0)) Session["TextBox1Value"] = rdr.getString(0);
if (!rdr.IsDbNull(1)) Session["TextBox2Value"] = rdr.getString(0);
}
}
PushSessionValuesToControls()
{
TextBox1.Text = (string) Session["TextBox1Value"];
TextBox2.Text = (string) Session["TextBox2Value"];
}
In this, the SessionVariables never get the values from the database ( even
though the database is correctly read )
I'm clearly way off the mark here, but don't know where.
Any suggestions?
Paul
it, and it screamed at me about directly using textbox.text values instead
of session values. So, I tried to re-write parts of it using session
variables and got no where.
The (Pseudo) code that doesn't work at all is as follows:
Page_Load( )
{
if ( !IsPostBack )
{
CreateSessionVariables();
LoadSessionVariablesFromDB();
PushSessionVariablesToControls();
}
else
{ PushSessionVariablesToControls(); }
}
TextBox1ON_TextChange( )
{ Session["TextBox1Value"] = TextBox1.Text; }
TextBox2On_TextChange( )
{ Session["TextBox2.Value"] = TextBox2.Text; }
ButtonSaveToDBOnClick()
{ PushSessionVariablesToDB() }
CreateSessionVariables()
{
Session["TextBox1Value"] = "";
Session["TextBox2Value"] = "";
}
LoadSessionVariablesFromDB()
{
string sql = "Select TB1Value, TB2Value from MYDB";
other sql stuff;
SqlDataReader rdr = .........;
if ( rdr.read() )
{
if (!rdr.IsDbNull(0)) Session["TextBox1Value"] = rdr.getString(0);
if (!rdr.IsDbNull(1)) Session["TextBox2Value"] = rdr.getString(0);
}
}
PushSessionValuesToControls()
{
TextBox1.Text = (string) Session["TextBox1Value"];
TextBox2.Text = (string) Session["TextBox2Value"];
}
In this, the SessionVariables never get the values from the database ( even
though the database is correctly read )
I'm clearly way off the mark here, but don't know where.
Any suggestions?
Paul