[Mono-list] ASP Server.Transfer error
Bryan Buchanan
bryanb at webbtide.com
Thu May 25 23:51:37 EDT 2006
Hi,
I'm trying to run the code from MS's web site on the topic "Passing
Server Control Values Between Pages".
When I click on the "Go to second page" button, the runtime barfs with
an error "System.InvalidCastException: Cannot cast from source type to
destination type".
I'm assuming it's the line of code:
fp = (FirstPageClass) Context.Handler;
Can someone tell me if these examples should work ? Below is the code
and info on the version of Mono I'm using.
Thanks,
Bryan
FirsPageClass.aspx:
<%@ Page Language="C#" Inherits="FirstPageClass" %>
<html>
<head>
</head>
<body>
<form runat="server">
First Name:
<asp:TextBox id="first" runat="server"></asp:TextBox>
<br />
Last Name:
<asp:TextBox id="last" runat="server"></asp:TextBox>
<br />
<asp:Button id="Button1" onclick="ButtonClicked" runat="server" Text="Go to second page"></asp:Button>
</form>
</body>
</html>
FirstPageClass.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class FirstPageClass : System.Web.UI.Page {
protected TextBox first;
protected TextBox last;
protected Button Button1;
public string FirstName {
get { return first.Text; }
}
public string LastName {
get { return last.Text; }
}
protected void ButtonClicked(object sender, EventArgs e) {
Server.Transfer("SecondPageClass.aspx");
}
}
SecondPageClass.aspx
<%@ Page Language="C#" Inherits="SecondPageClass" %>
<%@ reference page="FirstPageClass.aspx" %>
<html>
<head>
</head>
<body>
<form runat="server">
Hello <asp:Label id="label1" runat="server" text="Label"></asp:Label>
</form>
</body>
</html>
SecondPageClass.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class SecondPageClass : System.Web.UI.Page {
protected Label label1;
public FirstPageClass fp;
protected void Page_Load() {
if (!IsPostBack) {
fp = (FirstPageClass) Context.Handler;
label1.Text = fp.FirstName + " " + fp.LastName;
}
}
}
Mono and XSP version:
Mono JIT compiler version 1.1.15, (C) 2002-2005 Novell, Inc and Contributors. www.mono-project.com
TLS: normal
GC: Included Boehm (with typed GC)
SIGSEGV: normal
Disabled: none
xsp2.exe 1.1.13.0
(c) (c) 2002-2005 Novell, Inc.
Minimalistic web server for testing System.Web
More information about the Mono-list
mailing list