By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,491 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,491 IT Pros & Developers. It's quick & easy.

Need help understanding the use of session variables

P: n/a
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
Jan 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Can you link to the FxCop error in question

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Paul Rogers" <pr*****@fluiddynamics.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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

Jan 16 '06 #2

P: n/a
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:u1**************@TK2MSFTNGP09.phx.gbl...
Can you link to the FxCop error in question

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Paul Rogers" <pr*****@fluiddynamics.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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


Jan 16 '06 #3

P: n/a
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" <pr*****@fluiddynamics.com> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
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:u1**************@TK2MSFTNGP09.phx.gbl...
Can you link to the FxCop error in question

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Paul Rogers" <pr*****@fluiddynamics.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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



Jan 16 '06 #4

P: n/a
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:ev**************@TK2MSFTNGP10.phx.gbl...
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" <pr*****@fluiddynamics.com> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
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:u1**************@TK2MSFTNGP09.phx.gbl...
Can you link to the FxCop error in question

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Paul Rogers" <pr*****@fluiddynamics.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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



Jan 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.