type Casting in C#

I want to transfer data from one webpage to another webpage using Context.handler..

I got code from MSDN site like, in the calling form i wrote

public WebForm1 webform1_instance;

WebFrom1 webform1_instance = (WebForm1)Context.Handler

label2.text = webform1_instance.username_textbox.text.Tostring();

Then this coding gives error for : INVALID TYPE CASTING IN C#

FOR

WebFrom1 webform1_instance =(WebForm1)Context.Handler

nhow what should i do ,, please help me out.......

[562 byte] By [syParth] at [2007-12-29]
# 1

AFAIK you can't use Handler for that. The handler will be the handler for the current request and not necessarily a web page. You should instead rely on traditional methods for passing data between pages such as using Items for same-request information, Session for cross-request information or query string for general information.

Therefore your cast, although syntactically legal, is not valid and will never work.

Michael Taylor - 2/7/07
http://p3net.mvps.org

TaylorMichaelL at 2007-9-5 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2
Where you got error, on build or in runtime. Also be sure that you moved from WebFrom1 to the second web form where on Page_Load you execute this code which event is only place where this code will work. Also check if that Page_Load is not result of PostBack operation.
boban.s at 2007-9-5 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3

but this code is suggested by the msdn site... and woudl you please tell me , what is the reason , for not working? And please , if you can ,tel me the code by which i can get that problem solved..

I wnat to transfer a textbox's string to another page's label.text...

thanx verymuch..

syParth at 2007-9-5 > top of Msdn Tech,Visual C#,Visual C# Language...
# 4

Well,

This thread may help you out: http://forums.asp.net/thread/973632.aspx

Thank you

FigoFei-MSFT at 2007-9-5 > top of Msdn Tech,Visual C#,Visual C# Language...