Need help understanding the use of session variables

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
 
P

Paul Rogers

I just re-ran FXCop on the project and these errors didn't show up. Of
course most of the errors cited pointed to lines in the code having nothing
to do with the error, so I don't really know what was up.

In either case, is the approach I outlined below the correct one?

Thanks

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
Can you link to the FxCop error in question

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


Paul Rogers said:
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
 
K

Karl Seguin [MVP]

No. It seems overly complicated for no reason. I don't see why you'd use a
session variable for this (unless i'm not seeing the big picture). That's
why I was hoping the FxCop page might provide some better insight.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


Paul Rogers said:
I just re-ran FXCop on the project and these errors didn't show up. Of
course most of the errors cited pointed to lines in the code having nothing
to do with the error, so I don't really know what was up.

In either case, is the approach I outlined below the correct one?

Thanks

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
Can you link to the FxCop error in question

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


Paul Rogers said:
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
 
P

Paul Rogers

It didn't really make any sense to me either. In the solution I was
attempting to implement, I was still posting back to the server with the
contents of the text boxes as well as creating a session variable containing
the same contents. Thus, if there were security issues, they would be more
significant in the scenario where I was creating the session variables.
Additionally, these data are not session wide data, they are only relevant
to the specific entries on the incidence of the page just submitted, so it
made no sense to create session variables of them.

Anyway, thanks for your responses.

Paul



"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
No. It seems overly complicated for no reason. I don't see why you'd use a
session variable for this (unless i'm not seeing the big picture). That's
why I was hoping the FxCop page might provide some better insight.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


Paul Rogers said:
I just re-ran FXCop on the project and these errors didn't show up. Of
course most of the errors cited pointed to lines in the code having
nothing to do with the error, so I don't really know what was up.

In either case, is the approach I outlined below the correct one?

Thanks

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
Can you link to the FxCop error in question

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top