473,881 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invalid Cast Exception using Server.Transfer

I am attempting to pass data between two asp.net web forms pages. I
have found the method to do this on the msdn site here:

http://msdn.microsoft.com/library/de...tweenPages.asp

After attempting to do this myself, I kept getting an Invalid Cast
Exception error, so I finally resorted to simply copying and pasting
the MS code in this article into two pages for the purpose of testing.
Surprisingly, I found myself with the exact same invalid cast error. No
idea what I'm missing here.

Nov 19 '05 #1
9 2215
Buzz:

Do you know what line of code was throwing an InvalidCast error?

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

On 18 Mar 2005 08:20:35 -0800, "buzz" <rb*******@yaho o.com> wrote:
I am attempting to pass data between two asp.net web forms pages. I
have found the method to do this on the msdn site here:

http://msdn.microsoft.com/library/de...tweenPages.asp

After attempting to do this myself, I kept getting an Invalid Cast
Exception error, so I finally resorted to simply copying and pasting
the MS code in this article into two pages for the purpose of testing.
Surprisingly , I found myself with the exact same invalid cast error. No
idea what I'm missing here.


Nov 19 '05 #2
Line 16, where i am casting the Context.Handler to the classname
specified in the page directive of the sending page.

Nov 19 '05 #3
HI Buzz:

If it's a line like this:

FirstPageClass fp = (FirstPageClass )Context.Handle r;

then Handler isn't a FirstPageClass object. What was the name of the
webform class that did the Server.Transfer ?

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

On 18 Mar 2005 08:33:20 -0800, "buzz" <rb*******@yaho o.com> wrote:
Line 16, where i am casting the Context.Handler to the classname
specified in the page directive of the sending page.


Nov 19 '05 #4
Well, I'm presuming that the name of the webform class is the what was
specified as the ClassName="what ever" portion of the @ Page directive
on the sending page. At least, that is the way it is explained in the
article. Like I said in my original post, I copied the code from the
microsoft article exactly, so the ClassName in the page directive of
the sending page is "FirstPageClass "

My understanding was that the Context.Handler contained all the
pertinent info when the Server.Transfer took place, and that you needed
to create an instance of the sending page class, then set it equal to
the Context.Handler . Because the Context.Handler is generic, it has to
be cast as the sending page class in order to do this.

But that's where I have a problem. I'm just lost, given that the MS
code does the exact same thing. I haven't made any code changes to the
code they posted in the article.

Nov 19 '05 #5
Hi buzz:

On 18 Mar 2005 10:38:19 -0800, "buzz" <rb*******@yaho o.com> wrote:
Well, I'm presuming that the name of the webform class is the what was
specified as the ClassName="what ever" portion of the @ Page directive
on the sending page. At least, that is the way it is explained in the
article. Like I said in my original post, I copied the code from the
microsoft article exactly, so the ClassName in the page directive of
the sending page is "FirstPageClass "

Yes, that should be working for you then. I'm not sure what would be
going wrong.

My understanding was that the Context.Handler contained all the
pertinent info when the Server.Transfer took place, and that you needed
to create an instance of the sending page class, then set it equal to
the Context.Handler . Because the Context.Handler is generic, it has to
be cast as the sending page class in order to do this.

that's all correct, except your code doesn't need to create an
instance of the sending page class, it just declares a variable of the
type and gets the instance from Context.Handler .
But that's where I have a problem. I'm just lost, given that the MS
code does the exact same thing. I haven't made any code changes to the
code they posted in the article.


Are you using VisualStudio? In the debugger you can stop execution on
that line of code and inspect Context.Handler to get information about
it.

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

Nov 19 '05 #6
No, i'm not using studio. Just using DreamweaverMX using code view to
do my stuff. Actually, I've narrowed down the problem to something on
my laptop. I loaded the files up to a server and it worked ok. Not sure
what is different, or if there is maybe something I need to install on
my laptop??? Laptop is an XP Pro workstation... My web stuff has always
worked previously on my laptop...

Nov 19 '05 #7
Write out to the Trace or Response.write the Context.Handler type. Usually
ToString() will give you this.
"buzz" wrote:
No, i'm not using studio. Just using DreamweaverMX using code view to
do my stuff. Actually, I've narrowed down the problem to something on
my laptop. I loaded the files up to a server and it worked ok. Not sure
what is different, or if there is maybe something I need to install on
my laptop??? Laptop is an XP Pro workstation... My web stuff has always
worked previously on my laptop...

Nov 19 '05 #8
Well, i think i have it figured out. The problem was not with my code,
but rather with how i was accessing the pages. I was using the preview
function of Dreamweaver, which renders your page out to a temp file and
then displays it in a browser. That was my problem. The page reference
in the second page was not working because the first page was a temp
file. I accessed the pages normally using a browser, outside of DW, and
it worked perfectly. Thanks for all the suggestions.

Nov 19 '05 #9
Ah, I'm glad it's working now. It sounded like you had everything
lined up right.

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

On 18 Mar 2005 14:16:09 -0800, "buzz" <rb*******@yaho o.com> wrote:
Well, i think i have it figured out. The problem was not with my code,
but rather with how i was accessing the pages. I was using the preview
function of Dreamweaver, which renders your page out to a temp file and
then displays it in a browser. That was my problem. The page reference
in the second page was not working because the first page was a temp
file. I accessed the pages normally using a browser, outside of DW, and
it worked perfectly. Thanks for all the suggestions.


Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6335
by: | last post by:
When I execute the following (with an OleDBDataAdapter), wanting to add a row to a visual foxpro table: myrow= datasetTarget.Tables(0).NewRow 'fill all columns here like.. row(i)= myvalue ' then datasetTarget.Tables(0).Rows.Add(myrow) dataAdapterTarget.Update(datasetTarget.Tables(0)) '*
0
1187
by: Andrew | last post by:
Can someone out there help. I am using Server. Transfer from a user control to a webform and tried to follow many examples exactly as specified but cannot get around the (Specified cast is not valid.) ERROR which happens on the second page Search.aspx on the line with (PrevPageValues = (FirstPage)Context.Handler;). I have also got <%@ Reference Page="_FirstPage.ascx" %> at the top of the second page.
5
3447
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
2297
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring =
6
6052
by: vinay | last post by:
What is this error?? Exception Details: System.Web.HttpException: Unable to validate data. System.Web.Configuration.MachineKey.GetDecodedData(Byte buf, Byte modifier, Int32 start, Int32 length, Int32& dataLength) +195 System.Web.UI.LosFormatter.Deserialize(String input) +60
1
4922
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal iDate As Date) As String 'Dim Ret As Integer
15
2270
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed spectacularly. I was so embarrassed and felt like killing the person that made it fail. However, when it goes live, IT MUST NOT FAIL. The system has a backoffice system that takes an excel spreadsheet from the
9
4935
by: Jamie | last post by:
I am receiving an Invalid ViewState error after posting back to the same page twice. Consistently the error occurs after the second postback and not after the first. I have looked into creating a static machinekey in the machine.config and that did not help. I believe that issue only occurred when there was an inconsistent viewstate error. The error I am faced with consistently occurs. Are there any known problems with the ViewState...
9
6667
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its length is 642 bytes ( I have appended it to the end of this message). I suspect that the reason may have something to do with an incorrect declaration of which class to de-serialize to. In the attached code I substituted @@@@@@@ in the code below with...
0
9927
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10814
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10401
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7953
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.