473,394 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Need help understanding the use of session variables

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
4 1306
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave Smithz | last post by:
Hi there, I have implemented a login sequence using session variables for a PHP/MySQL DB which I took over development. I read some books and this NG and it seemed straight forward. However the...
6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
4
by: PJ | last post by:
A particular page seems to be having issues with correctly setting Session variables. I am setting a couple of session variables on the Page_Unload event. While stepping through code, the...
2
by: Boban Dragojlovic | last post by:
I'm building a complex web-based reservations system. Gathering the user's data requires between 8 and 15 pages (depending on which options they are interested in). I use the "Session" object to...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
2
by: rodchar | last post by:
hey all, i have a simple app that references the web.config. i browse to the page. i changed the web.config. i do a postback to the page, And session is gone. Only after i close the browser...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
3
by: Phillip N Rounds | last post by:
I'm writing a user control which has two states: Active & InActive. I additionally am required that there to be only one active control per page, and all logic has to be contained within the...
26
by: BillE | last post by:
Some ASP.NET applications use Session Variables extensively to maintain state. These should be re-written to use viewstate, hidden fields, querystring, etc. instead. This is because if a user...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.