Thursday, March 29, 2012

session value lost

Hello NG,

I have three files (default.aspx, search.aspx and work.aspx). The way
is: login on default (if session is newsession). The loginname I write
into as sessionvariable (username). So I redirect to my search.aspx.
Here I have a form which allows fill in some fields (place, street,
name etc.). With this informations i build a sqlquerey for sqlserver,
fill a datagrid and after select the right record by usin a link behind
I save the recordid to the session and redirect to work.aspx. With a
new sqlstring I fetch the data from the sqlserver. But this data is
only to display. The user can edit Data for a new record in anoter
table and end it wiht button click. Here I will save all sessionvalues
(username, and recordinformation) with sqlstring and redirect to
search.aspx.

Now the problems:
1. I don't no what I've changed - but I have to...
After redirection from work to search I've got an sql-error. The string
will be cleard before building new, so why does it run once, but not
after redirect?
2. I solved this problem with redirecting from work to default. Its
running. But: the session username is empty - why?
3. I solved with writing the username in an hidden field on
default.aspx, read it again and write to session. Everything is fine.
4. Now we can work, and I will change the username from manuel login to
reading from client windows. But I realy want to know why I have the
Problems 1 to 3 and problem no 4 is: some stored records have no
username within. Who can explain it to me - who as a solution to solve
the problems?You might want to share the source code for your search.aspx page so
we can look it over.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 27 Jun 2005 07:46:30 -0700, "catweezle2010" <catweezle2010@.gmx.de>
wrote:

>Hello NG,
>I have three files (default.aspx, search.aspx and work.aspx). The way
>is: login on default (if session is newsession). The loginname I write
>into as sessionvariable (username). So I redirect to my search.aspx.
>Here I have a form which allows fill in some fields (place, street,
>name etc.). With this informations i build a sqlquerey for sqlserver,
>fill a datagrid and after select the right record by usin a link behind
>I save the recordid to the session and redirect to work.aspx. With a
>new sqlstring I fetch the data from the sqlserver. But this data is
>only to display. The user can edit Data for a new record in anoter
>table and end it wiht button click. Here I will save all sessionvalues
>(username, and recordinformation) with sqlstring and redirect to
>search.aspx.
>Now the problems:
>1. I don't no what I've changed - but I have to...
>After redirection from work to search I've got an sql-error. The string
>will be cleard before building new, so why does it run once, but not
>after redirect?
>2. I solved this problem with redirecting from work to default. Its
>running. But: the session username is empty - why?
>3. I solved with writing the username in an hidden field on
>default.aspx, read it again and write to session. Everything is fine.
>4. Now we can work, and I will change the username from manuel login to
>reading from client windows. But I realy want to know why I have the
>Problems 1 to 3 and problem no 4 is: some stored records have no
>username within. Who can explain it to me - who as a solution to solve
>the problems?
Hi Allen,

it will be to much code but I think, it's better for understanding:

I start with the default.aspx. If the session is new, nothing will
happen unless the user logs in - no problem. When I come from my last
page (call.aspx) the sessionvariable 'user' has still a value. When I
redirect to my second page (suche.aspx) this value will be lost. So I
do this workaround:

default.aspx

Sub Page_Load (ByVal Sender As Object, _
ByVal E As EventArgs)

Session("KD_VNAME")=""
Session("KD_NAME")=""
Session("STADT")=""
Session("PLZ")=""
Session("STRASSE")=""

If Session.IsNewSession Then
TextBox1.value="neu"
else
if ispostback then
Session("Anwendername") = TextBoxLogin.value
TextBox1.value=Session("Anwendername")
response.redirect("suche.aspx")
else
TextBox1.value=Session("Anwendername")
Session("Anwendername") = TextBox1.value
response.redirect("suche.aspx")
end if
end if

When loading the suche.aspx I check on newsession and if not I will
clear the value of some session varialbes:

suche.aspx

Sub Page_Load (ByVal Sender As Object, _
ByVal E As EventArgs)

If Session.IsNewSession Then
response.redirect("default.aspx")
else
dataSet
end if
end sub

public sub DataSet()
Session("KD_VNAME")=""
Session("KD_NAME")=""
Session("STADT")=""
Session("PLZ")=""
Session("STRASSE")=""
Datagrid1.DataBind()
end sub

After the user filled in the search date the function will be called.
First I had a redirect form my last page (call.aspx) back to this one.
If I am first on the page everything is fine. The second time, after
redirect I get an error, which means the sql statement is incorrect.
But there can no old value - I clear it. So I redirect to the
default.aspx:

function DatenSuche() As System.Data.IDataReader
Dim connectionString As String = "Data Source=mssql;Initial
Catalog=DB;User Id=huser;Password=passw;Connect Timeout=15;Network
Library=dbmssocn;"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = ""
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand

if TextBox_Name.text <> "" then
if queryString <> "" then
queryString = querystring & " and "
end if
queryString = queryString & "[KD_NAME] like N'" & TextBox_Name.text
& "%' "
end if
if TextBox_Vorname.text <> "" then
if queryString <> "" then
queryString = querystring & " and "
end if
queryString = queryString & "[KD_VNAME] like N'" &
TextBox_Vorname.text & "%' "
end if

queryString = "SELECT [View_Such].* FROM [View_Such] WHERE (" &
queryString & ")"
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
Return dataReader
dataReader.close
dbConnection.close
connectionString = ""
queryString = ""
end function

call.aspx

public sub ButtonEnde_Click(sender As Object, e As EventArgs)
response.redirect("default.aspx")
'response.redirect("suche.aspx")
end sub

Any idea?
One thing you may want to try is to use:

Response.Redirect("page", False);

Whenever you are in a page where the user might have started a
session. See:
http://weblogs.asp.net/bleroy/archi.../03/207486.aspx

Another approach I'd try is to not use so many redirects, but drop a
panel control on your form and keep the search results inside the
panel. You can set the Visible property of the panel to false, and
toggle the value to true when there are search results to display.
This might make the page easier to work with.

--
Scott
http://www.OdeToCode.com/blogs/scott/]

On 29 Jun 2005 04:04:53 -0700, "catweezle2010" <catweezle2010@.gmx.de>
wrote:

>Hi Allen,
>it will be to much code but I think, it's better for understanding:
>I start with the default.aspx. If the session is new, nothing will
>happen unless the user logs in - no problem. When I come from my last
>page (call.aspx) the sessionvariable 'user' has still a value. When I
>redirect to my second page (suche.aspx) this value will be lost. So I
>do this workaround:
>default.aspx
>Sub Page_Load (ByVal Sender As Object, _
> ByVal E As EventArgs)
> Session("KD_VNAME")=""
> Session("KD_NAME")=""
> Session("STADT")=""
> Session("PLZ")=""
> Session("STRASSE")=""
>If Session.IsNewSession Then
> TextBox1.value="neu"
> else
> if ispostback then
> Session("Anwendername") = TextBoxLogin.value
> TextBox1.value=Session("Anwendername")
> response.redirect("suche.aspx")
> else
> TextBox1.value=Session("Anwendername")
> Session("Anwendername") = TextBox1.value
> response.redirect("suche.aspx")
> end if
> end if
>When loading the suche.aspx I check on newsession and if not I will
>clear the value of some session varialbes:
>suche.aspx
>Sub Page_Load (ByVal Sender As Object, _
> ByVal E As EventArgs)
>If Session.IsNewSession Then
> response.redirect("default.aspx")
> else
> dataSet
> end if
>end sub
>public sub DataSet()
>Session("KD_VNAME")=""
> Session("KD_NAME")=""
> Session("STADT")=""
> Session("PLZ")=""
> Session("STRASSE")=""
> Datagrid1.DataBind()
>end sub
>
>After the user filled in the search date the function will be called.
>First I had a redirect form my last page (call.aspx) back to this one.
>If I am first on the page everything is fine. The second time, after
>redirect I get an error, which means the sql statement is incorrect.
>But there can no old value - I clear it. So I redirect to the
>default.aspx:
>function DatenSuche() As System.Data.IDataReader
> Dim connectionString As String = "Data Source=mssql;Initial
>Catalog=DB;User Id=huser;Password=passw;Connect Timeout=15;Network
>Library=dbmssocn;"
> Dim dbConnection As System.Data.IDbConnection = New
>System.Data.SqlClient.SqlConnection(connectionStri ng)
> Dim queryString As String = ""
> Dim dbCommand As System.Data.IDbCommand = New
>System.Data.SqlClient.SqlCommand
> if TextBox_Name.text <> "" then
>if queryString <> "" then
> queryString = querystring & " and "
> end if
> queryString = queryString & "[KD_NAME] like N'" & TextBox_Name.text
>& "%' "
> end if
> if TextBox_Vorname.text <> "" then
> if queryString <> "" then
> queryString = querystring & " and "
> end if
> queryString = queryString & "[KD_VNAME] like N'" &
>TextBox_Vorname.text & "%' "
> end if
>
> queryString = "SELECT [View_Such].* FROM [View_Such] WHERE (" &
>queryString & ")"
> dbCommand.CommandText = queryString
> dbCommand.Connection = dbConnection
> dbConnection.Open
> Dim dataReader As System.Data.IDataReader =
>dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
> Return dataReader
> dataReader.close
> dbConnection.close
> connectionString = ""
> queryString = ""
>end function
>
>call.aspx
>public sub ButtonEnde_Click(sender As Object, e As EventArgs)
> response.redirect("default.aspx")
> 'response.redirect("suche.aspx")
> end sub
>
>
>Any idea?

0 comments:

Post a Comment