Siv
asked on
ASP.NET PreviousPage question
Hi,
I have a first page with a ListView on it that has a "select" entry in the first column that uses a LinkButton which when clicked triggers the SelectedIndexChanging event. A code behind routine stores the Database ID field of the row being selected in a public Property of the first page called "SelID". That's working fine.
After storing the SelID I then go to the second page (using a response.redirect). In the Page_Load of the second page I then want to pick up the SelID from the previous page and use that to populate my screen from the database. For some unknown reason when I test the PreviousPage it's always set at Nothing?
I have added the following line to the top of the second page's source:
<%@ PreviousPageType VirtualPath="~/firstPage.a spx" %>
Is it down to the fact that I have used a response.redirect or am I missing something else?
Any Help appreciated,
Siv
I have a first page with a ListView on it that has a "select" entry in the first column that uses a LinkButton which when clicked triggers the SelectedIndexChanging event. A code behind routine stores the Database ID field of the row being selected in a public Property of the first page called "SelID". That's working fine.
After storing the SelID I then go to the second page (using a response.redirect). In the Page_Load of the second page I then want to pick up the SelID from the previous page and use that to populate my screen from the database. For some unknown reason when I test the PreviousPage it's always set at Nothing?
I have added the following line to the top of the second page's source:
<%@ PreviousPageType VirtualPath="~/firstPage.a
Is it down to the fact that I have used a response.redirect or am I missing something else?
Any Help appreciated,
Siv
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Dear Siv,
As per provided Stack trace, there is some issue with cboCustomerNames:
InnerException: System.ArgumentOutOfRangeE xception
HResult=-2146233086
Message='cboCustomerNames' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
ParamName=value
Source=System.Web
Thanks
As per provided Stack trace, there is some issue with cboCustomerNames:
InnerException: System.ArgumentOutOfRangeE
HResult=-2146233086
Message='cboCustomerNames'
Parameter name: value
ParamName=value
Source=System.Web
Thanks
ASKER
Imran,
I saw that but assumed that as the error was occurring on the call to the Server.Transfer it was something to do with the transfer not the issue on the population of the new page. If that's what it is then I am OK as I know what that issue is.
Thanks for your help, I can now move on again.
What you have shown me has cured the main issue of the PreviousPage being set to nothing.
I will award you the points for solving the problem for me.
If you have time could you answer one more question; in your opinion is there any benefit or penalty of using Server.transfer as opposed to response.redirect? Given that this method works I am now considering using Server.Transfer all the time as often I need to access properties from one page on another.
I prefer not to use QueryStrings as a) it looks messy for the user and more importantly b) seems to be a bit of a security risk as it may expose some of the internal workings of a page.
Siv
I saw that but assumed that as the error was occurring on the call to the Server.Transfer it was something to do with the transfer not the issue on the population of the new page. If that's what it is then I am OK as I know what that issue is.
Thanks for your help, I can now move on again.
What you have shown me has cured the main issue of the PreviousPage being set to nothing.
I will award you the points for solving the problem for me.
If you have time could you answer one more question; in your opinion is there any benefit or penalty of using Server.transfer as opposed to response.redirect? Given that this method works I am now considering using Server.Transfer all the time as often I need to access properties from one page on another.
I prefer not to use QueryStrings as a) it looks messy for the user and more importantly b) seems to be a bit of a security risk as it may expose some of the internal workings of a page.
Siv
ASKER
Imran,
Thanks for your help and patience as I worked through this.
Server.Transfer seems to be the way to go in future.
Siv
Thanks for your help and patience as I worked through this.
Server.Transfer seems to be the way to go in future.
Siv
My pleasure, Hope you may find following helpful:
http://www.codeproject.com/Questions/420469/Response-Redirect-and-Server-Transfer
stackoverflow.com/question s/6778870/ difference -between-r esponse-re direct-and -server-tr ansfer
Thanks
http://www.codeproject.com/Questions/420469/Response-Redirect-and-Server-Transfer
stackoverflow.com/question
Thanks
ASKER
Imran,
Thanks, I'll stick with Server.transfer as it seems better all round as long as your not going to a different server which I never will be.
Siv
Thanks, I'll stick with Server.transfer as it seems better all round as long as your not going to a different server which I never will be.
Siv
ASKER
I changed my code in the SelectedIndexChanging event from:
Dim item As ListViewItem
Dim lbl As Label
'Store the Selected Item in the public property.
item = lstIncidentReports.Items(e
lbl = item.FindControl("Incident
SelID = CType(lbl.Text, Integer)
Response.Redirect("frmInci
To:
Dim item As ListViewItem
Dim lbl As Label
'Store the Selected Item in the public property.
item = lstIncidentReports.Items(e
lbl = item.FindControl("Incident
SelID = CType(lbl.Text, Integer)
Server.Transfer("frmIncide
However when I ran the code and get this error on the Server.transfer line:
System.Web.HttpException was unhandled by user code
ErrorCode=-2147467259
HResult=-2147467259
Message=Error executing child request for frmIncidentReportP2.aspx.
Source=System.Web
WebEventCode=0
StackTrace:
at System.Web.HttpServerUtili
at System.Web.HttpServerUtili
at System.Web.HttpServerUtili
at _Default.lstIncidentReport
at System.EventHandler`1.Invo
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.Control.Rais
at System.Web.UI.WebControls.
at System.Web.UI.Control.Rais
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.Page.RaisePo
at System.Web.UI.Page.RaisePo
at System.Web.UI.Page.Process
InnerException: System.Web.HttpUnhandledEx
ErrorCode=-2147467259
HResult=-2147467259
Message=Exception of type 'System.Web.HttpUnhandledE
Source=System.Web
WebEventCode=0
StackTrace:
at System.Web.UI.Page.HandleE
at System.Web.UI.Page.Process
at System.Web.UI.Page.Process
at System.Web.UI.Page.Process
at System.Web.UI.Page.Process
at System.Web.UI.Page.Process
at ASP.frmincidentreportp2_as
at System.Web.HttpServerUtili
InnerException: System.ArgumentOutOfRangeE
HResult=-2146233086
Message='cboCustomerNames'
Parameter name: value
ParamName=value
Source=System.Web
StackTrace:
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.WebControls.
at System.Web.UI.Control.PreR
at System.Web.UI.Control.PreR
at System.Web.UI.Control.PreR
at System.Web.UI.Control.PreR
at System.Web.UI.Control.PreR
at System.Web.UI.Control.PreR
at System.Web.UI.Page.Process
InnerException:
If I step the code It seems to get to the frmIncidentReportP2.aspx page and this time the PreviousPage is not nothing so the Page_Load of the new page works but then it returns to this routine with an error?
The code in the page_load is this:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If IsNothing(Session("LoggedI
Response.Redirect("NotLogg
Else
If Not IsNothing(PreviousPage) Then
If PreviousPage.SelID <> 0 Then
'We are showing an existing item.
PopulateScreen(PreviousPag
Else
'we are not
ClearScreen()
End If
End If
End If
End Sub
interestingly the above code executes and calls a routine to populate the screen using the SelID from the first page so it's all working, it just errors when that completes and I would expect the second page to appear?
So we get to the new page, execute the stuff in the Page_Load and when that completes instead of control being passed to the new page the code goes back to the previous page and errors on the Server.Transfer call??
Any idea what I am doing wrong?
Siv