Casting Error

M

mohit

I am making a web application in .NET framework.
I want to pass an information from one page to another page.
I have a class MsgClass in a page and in the another page I created an
object of this class
MsgClass mc;
for handeling I am using the following code

void Page_Load()
{


if (!IsPostBack)
{
mc = (MsgClass)Context.Handler;
}
}
it is giving the error

Error is : System.InvalidCastException: Specified cast is not valid.

then how to cast it.

any Ideas???
 
A

albert braun

I think it's because Context.Handler isn't a MsgClass object, so the
cast fails.

Why not use either the Session object or the Cache object to pass data
from one page to the next?

e.g. :
void Page_Load()
{
if (!IsPostBack)
{
mc = (MsgClass)Context.Session["myMsg"];
}
}

of course, in a previous page's Page_Load you'd have to have something
like:
Context.Session.Add("myMsg", MyMsgClassObj);
 
M

mohit

Thank You.Your suggetion is working.That was my silly mistake due to my
bad programing.
Bye...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Casting!!!?!?!?!? 1
Casting problem 0
Casting question 2
Error Using BreadCrumb 1
Problem adding/casting web user controls 0
casting ostream 7
Casting DataGridItem 3
Image overlay and comparison code error. 2

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top