473,847 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I get the following error ( Specified cast is not valid ) with Server.Transfer

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)Cont ext.Handler;).

I have also got <%@ Reference Page="_FirstPag e.ascx" %> at the top of
the second page.

This was an example from Microsoft which I followed as closely as
possible.
Any help would be appreciated


<!-- First Page-->############## ############### ############### ############### #
namespace Project
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

/// <summary>
/// Summary description for FirstPage.
/// </summary>
public abstract class FirstPage : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Drop DownList Category;
protected System.Web.UI.W ebControls.Text Box Seek;
protected System.Web.UI.W ebControls.Imag eButton SubmitBtn;

private void Page_Load(objec t sender, System.EventArg s e)
{
if (Page.IsPostBac k == false)
{
}
}

public string TheCat
{
get
{
return Category.Select edItem.Value.To String();
}
}

public string TheSeek
{
get
{
return Seek.Text;
}
}

//*************** *************** *************** **********
//
// The SubmitBtn_Click event handler is used on this page to
// search for the content in the database.
//
//*************** *************** *************** **********

void SubmitBtn_Click (object sender, System.Web.UI.I mageClickEventA rgs
e)
{
Server.Transfer ("SecondPage.as px");
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.SubmitBtn. Click += new
System.Web.UI.I mageClickEventH andler(this.Sub mitBtn_Click);
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
}
}

<!-- End First Page-->############## ############### ############### ############

<!-- Start Second Page-->############## ############### ############### #########
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace Project
{
/// <summary>
/// Summary description for Search.
/// </summary>
public class SecondPage : System.Web.UI.P age
{

protected System.Web.UI.W ebControls.Labe l MyLabel;
public FirstPage PrevPageValues;
void Page_Load(objec t sender, System.EventArg s e)
{

if (!IsPostBack)
{

//try
//{
PrevPageValues = (FirstPage)Cont ext.Handler;
MyLabel.Text = "" + PrevPageValues. TheCat + " " +
PrevPageValues. TheSeek + "";
//}
//catch (Exception ex)
//{
// MyLabel.Text = "Error";
//}

}

}

//*************** *************** *************** **********
//
// The SubmitBtn_Click event handler is used on this page to
// search for the content in the Teamissue database.
//
//*************** *************** *************** **********

private void SubmitBtn_Click (object sender,
System.Web.UI.I mageClickEventA rgs e)
{
if (Page.IsValid == true)
{

}

}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.SubmitBtn. Click += new
System.Web.UI.I mageClickEventH andler(this.Sub mitBtn_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}

}
<!-- End Second Page-->############## ############### ############### ###########
Nov 17 '05 #1
0 1186

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

Similar topics

13
3331
by: LL | last post by:
Hi, How to fix this problem: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid.
5
3980
by: .Net Sports | last post by:
I have a datagrid codebehind script that takes data from sql dbase and displays it in a footer row as a total. One column has amount_dollars (which works fine), while another has new sales (which is "newstotal"), but I'm getting an error (System.InvalidCastException: Specified cast is not valid) from the newstotal line: price = (Decimal)(rowData); newstotal = (rowData); newstotal is an integer, just wondering what datatype i should use
4
5767
by: SRLoka | last post by:
I have an application that has five threads. All five threads write to the same MSMQ. All five threads are using the same global instance to send data to the MSMQ server(on same machine). Occasionally, I get the erroror below. The data(string) being sent is not null or empty. Is this a problem related to multiple threads ? Right now I have coded it like this Controller.MSMQ.Send(Record); Should I change to
8
1967
by: Chris | last post by:
Hi, I have two froms (form1 and form2). I want to be able to pass values from form 1 to form2 and be able to use those values leter in form2. This is my code for form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Server.Transfer("form2.aspx", True) End Sub
1
1406
by: .Net Sports | last post by:
I have a datagrid codebehind script that takes data from sql dbase and displays it in a footer row as a total. One column has amount_dollars (which works fine), while another has new sales (which is "newstotal"), but I'm getting an error (System.InvalidCastException: Specified cast is not valid) from the newstotal line: price = (Decimal)(rowData); newstotal = (rowData); newstotal is an integer, just wondering what datatype i should use
0
1978
by: kcm | last post by:
Hello all, Not sure if this is the right place to post this. I ran up the samples for adventureworks for MSSQL2005. I setup the shop front. The web site is up. But when I try to register a new user via the web page I get this error. Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it...
3
3701
by: keithb | last post by:
Using a GridView, I get a "Specified cast is not valid" error when binding the Visible propery of a hyperlink control to a DataTable text field. The error goes away if I replace the data binding statement with "true" or "false". This code causes the error: <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("c2Hyperlink1Link") %>' Target="_blank"
1
4446
vinci
by: vinci | last post by:
Please help me out... i only have two weeks to do it... here is my code: Dim ex As New Object Dim wb As Excel.Workbook Dim sheet As Excel.Worksheet
3
1568
by: Zubulake | last post by:
i am throwing a exception error: Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid. this is my code.. <asp:Content ID="Content1" runat="server"...
0
9892
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
9734
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
10995
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10718
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
10347
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...
0
9493
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7061
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3168
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.