Solved

ASP.NET 4.00 Losing Public Property Values When clicking button to display next page?

Posted on 2014-01-21
6
497 Views
Last Modified: 2014-01-21
Hi,
I have a page with a public property that stores the ID of the record I am displaying.  When I click a button to move off that page I want to read the value of that property so that I can use it to get the data on the next page. What I am finding is that the property holds the ID right up to the moment I click the button that triggers the switch to the next page.  I am using Server.Transfer("frmIncidentReportP3.aspx", True) in the click event of the button that transfers me from the first to the second page.

In the top of the new page I have this:
<%@ PreviousPageType VirtualPath="~/frmIncidentReportP2.aspx" %>

And in the Page_Load of the new page I have:

        If Not IsNothing(PreviousPage) Then
            If PreviousPage.IncidentReportID > 0 Then
                Me.IncidentReportID = PreviousPage.IncidentReportID
            End If
        End If

The issue is that just prior to clicking the button IncidentReportID in "frmIncidentReportP2.aspx" holds the ID value, the moment I click the button it zeros so that by the time I get to the new page its value is lost.

What am I missing, why does the click of the button on the first page cause the Public property to instantly lose its value?

Siv
0
Comment
Question by:Siv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:fostersoft
ID: 39798978
I think its because you page is an object. When you call the other page, the current page(object) is close and loose is property. If you want to keep the value you can put it in the viewstate, or you can pass the parameter in the url QueryString parameter.


I hope i help you. If you need more information i'll be happy to give you some example.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 39799010
Using Server.Transfer you can access previous page control values but not a code-behind variable like you are trying to do.
A work-around would be to have a hidden field on your first page populated with the ID that you then can access it from the second page using findcontrol :

If Not IsNothing(PreviousPage) Then
    HiddenField hfIncidentReportId = (HiddenField)PreviousPage.FindControl
("hfIncidentReportId");
    If hfIncidentReportId.Value > 0 Then
         Me.IncidentReportID = hfIncidentReportId.Value
End If

Open in new window


Another alternative would to be to use a session object to store the ID.
0
 

Author Comment

by:Siv
ID: 39799075
Paul,
That was the answer, I changed the code to:

        If Page.IsPostBack Then
            Exit Sub
        End If
        Dim hf As HiddenField
        If Not IsNothing(PreviousPage) Then
            hf = PreviousPage.FindControl("hfIncidentReportID")
            If hf.Value <> "" Then
                If hf.Value > 0 Then
                    Me.IncidentReportID = hf.Value
                End If
            Else
                Me.IncidentReportID = 0
            End If
        End If

        If Not IsNothing(PreviousPage) Then
            hf = PreviousPage.FindControl("hfActionID")
            If hf.Value <> "" Then
                If hf.Value > 0 Then
                    Me.ActionCalendarID = hf.Value
                End If
            Else
                Me.ActionCalendarID = 0
            End If
        End If

Now what I intended is working!
Brilliant!

Thanks for your help!

Siv
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Closing Comment

by:Siv
ID: 39799077
Thanks, this lead me to the solution using PreviousPage.FindControl("HiddenControlName") now my ASP pages are behaving as expected.

Siv
0
 
LVL 4

Expert Comment

by:ItWorked
ID: 39799079
Yes @Paul Jackson is right.
You can have your data on server only if you have used ViewState(which is helpful only for single page) or You try to postback data to another page.

So to get the data in next page(second) you must have a control which can postback the data.
0
 

Author Comment

by:Siv
ID: 39799081
@fostersoft,

Thanks for your reply, I found that Paul Jackson's solution worked best for me as I don't want to use QueryStrings.

Siv
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question