473,396 Members | 1,935 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,396 software developers and data experts.

casting to page in class library


In my class library I need to access my current Webform (class). As I am
using HttpHandler for ASPX page, following lines of code are throwing error
that {"Specified cast is not valid." }.

// BasePage is custom class derived from Page
BasePage page = (BasePage) System.Web.HttpContext.Current.Handler;

Here System.Web.HttpContext.Current.Handler is returning handler and that is
why not able to cast to page.

How do I get a reference to current executing page in class library?

Any help would greatly be appreciated.

--
Thanks,
Mahesh

Nov 19 '05 #1
2 1619
How is this class library used? From an ASPX page or a class that is used as
an HTTPHandler or HTTPModule? Or, is it out by itself?

The reason I ask, is it is often easiest to pass in the page, by ref, rather
than set up an intricate setup to figure it out from a class called from the
page or HTTP_____. The reason is the wiring is already in place for both Page
and HTTP_____ classes.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Mahesh Nimbalkar" wrote:

In my class library I need to access my current Webform (class). As I am
using HttpHandler for ASPX page, following lines of code are throwing error
that {"Specified cast is not valid." }.

// BasePage is custom class derived from Page
BasePage page = (BasePage) System.Web.HttpContext.Current.Handler;

Here System.Web.HttpContext.Current.Handler is returning handler and that is
why not able to cast to page.

How do I get a reference to current executing page in class library?

Any help would greatly be appreciated.

--
Thanks,
Mahesh

Nov 19 '05 #2
Thanks for your reply Gregory.

At the end of the day and unfortunately I had to send page as a parameter to
the procedure in class library.

--
Thanks,
Mahesh

"Cowboy (Gregory A. Beamer) - MVP" wrote:
How is this class library used? From an ASPX page or a class that is used as
an HTTPHandler or HTTPModule? Or, is it out by itself?

The reason I ask, is it is often easiest to pass in the page, by ref, rather
than set up an intricate setup to figure it out from a class called from the
page or HTTP_____. The reason is the wiring is already in place for both Page
and HTTP_____ classes.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Mahesh Nimbalkar" wrote:

In my class library I need to access my current Webform (class). As I am
using HttpHandler for ASPX page, following lines of code are throwing error
that {"Specified cast is not valid." }.

// BasePage is custom class derived from Page
BasePage page = (BasePage) System.Web.HttpContext.Current.Handler;

Here System.Web.HttpContext.Current.Handler is returning handler and that is
why not able to cast to page.

How do I get a reference to current executing page in class library?

Any help would greatly be appreciated.

--
Thanks,
Mahesh

Nov 19 '05 #3

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

Similar topics

3
by: Andy Lomax | last post by:
I'm using a library where the supplier has provided base class 'foo', and a reference counting class which wraps 'foo': ------------------- library code ----------------------- template<class T>...
7
by: Andrew | last post by:
created a custom class that is derived from TreeNode, let's call it customTreeNode. I'm trying to use the TreeViewEventArgs (for the AfterSelect event) but I cannot cast to my derived TreeNode. ...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
61
by: Ken Allen | last post by:
I am relatively new to .Net, but have been using VB and C/C++ for years. One of the drawbacks with VB6 and earlier was the difficulty in casting a 'record' to a different 'shape' so one could...
7
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service...
7
by: S. Lorétan | last post by:
Hi guys, Sorry for this stupid question, but I don't know why it isn't working. Here is my (example) code: namespace Test { class A { public string Label1; }
8
by: mfc | last post by:
Suppose I have a Cookie class and a Factory Class. There are many types of Cookies and maybe one or more Factories with a ProcessCookie Method. Suppose all the PutInBox method does is decide what...
5
by: petethebloke | last post by:
I'm not sure how to ask for what I want, so I can't find it on Google. I'll explain..... I have a class 'hanging' with a constructor: class hanging{ function hanging(){ }
19
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting more often than creating an instance of objects. like : protected void gvOrderDetailsRowDataBound(object sender,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.