468,738 Members | 1,753 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

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 1039

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by LL | last post: by
5 posts views Thread by .Net Sports | last post: by
4 posts views Thread by SRLoka | last post: by
1 post views Thread by .Net Sports | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.