Server.Transer/Context.Handler

MTSkull

Centurion
Joined
Mar 25, 2003
Messages
151
Location
Boulder, Colorado
I have a web form that takes in user input. Then I transfer to a Processing page that tells the user to wait while some stuff is happening, and plays a simple flash animation.

Source page (GenerateMR)
Code:
protected void cmdGenerateMR_Click(object sender, EventArgs e)
        {
            Server.Transfer("MRProcessing.aspx",true);
        }

Then I try to set an object on the destination page so I can read back the values entered on the source page.
Destination Page (MRProcessing)
Code:
        private GenerateMR frmSource;
        
        protected void Page_Load(object sender, EventArgs e)
        {            
            if (IsPostBack)
                return;

            //Following throws InvalidCastException
            //Unable to cast object of type 'ASP.fieldservice_generatemr_aspx' to type 'FieldReturns.GenerateMR'.
            //frmSource = (GenerateMR)Context.Handler;

            //also generates above error..
            GenerateMR frmSource = (GenerateMR)PreviousPage;
        }

Basically I want to switch to a "Processing files, Please Wait" Page while I am doing stuff on the server. Is this method a good fit, if I can get it working or should I be doing something else.

Thanks
MTS
 
Fixed...

I could not find anyone who had a similar problem, despite hours running various Google searches. I thought I might have a corrupt install or something, so I created a project to test the PreviousPage property and Source.Transfer() function, while stripping away everything else that was irrelevant to the problem. Everything worked as expected.

Then I looked closer at the error message and noticed that "ASP.fieldservice_generatemr_aspx" seemed to point to the wrong location. It should have been ASP.fieldservice_SUBFOLDER_generatemr_aspx. Which lead me to suspect I had created the error, which is usually the problem.

About a month ago I had moved the source page file into a sub folder in the project after I had created the page. When you create the page the project knows where it is. Then when you move it (drag and drop to new folder) something does not get updated with the new location. When you try to use
Code:
<%@ PreviousPageType VirtualPath="SourcePage.aspx" %>
the program freaks out because it cannot find the source form and cannot cast the page to the appropriate object. I could not find where the update to reflect the move needed to occur (didn't really look:rolleyes:) so to fix I renamed the old page and recreated a new page with the old pages original name. Then copied and pasted the code from the old to the new and presto, everything started working as expected.

I should start a blog "How not to code ASPX pages."
MTS
 
Back
Top