473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

I have also got <%@ Reference Page="_FirstPage.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.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for FirstPage.
/// </summary>
public abstract class FirstPage : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DropDownList Category;
protected System.Web.UI.WebControls.TextBox Seek;
protected System.Web.UI.WebControls.ImageButton SubmitBtn;

private void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack == false)
{
}
}

public string TheCat
{
get
{
return Category.SelectedItem.Value.ToString();
}
}

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.ImageClickEventArgs
e)
{
Server.Transfer("SecondPage.aspx");
}

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

/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SubmitBtn.Click += new
System.Web.UI.ImageClickEventHandler(this.SubmitBt n_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}

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

<!-- Start Second Page-->################################################# ####
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

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

protected System.Web.UI.WebControls.Label MyLabel;
public FirstPage PrevPageValues;
void Page_Load(object sender, System.EventArgs e)
{

if (!IsPostBack)
{

//try
//{
PrevPageValues = (FirstPage)Context.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.ImageClickEventArgs e)
{
if (Page.IsValid == true)
{

}

}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SubmitBtn.Click += new
System.Web.UI.ImageClickEventHandler(this.SubmitBt n_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}

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

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

Similar topics

13
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...
5
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...
4
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)....
8
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...
1
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...
0
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...
3
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...
1
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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,...
0
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...

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.