473,804 Members | 4,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine calling page

I am using "Server.Transfe r()" to send data to an ASP.NET page that's
sole purpose is to display messages. I am using "Server.Transfe r since I
can set the contents of the message I want to display via the properties
of the page that is initiating the Server.Transfer () and also because
large amounts of data can be sent, such as a datagrid or other object.
Here is an example...
/* Sending Page (GenerateMessag e.aspx) */

private string mMsg1 = "This is the first message";
private string mMsg2 = "This is the second message";

public string Message1
{
Get {return mMsg1;}
}

public string Message2
{
Get {return mMsg2;}
}
Server.Transfer ("DisplayMessag Â*es.aspx");

/* Receiving Page (DisplayMessage s.aspx) */

GenerateMessage objPage = (GenerateMessag e)Context.Handl Â*er;
Response.Write( "<B>" + objPage.Message 1 + "</B>");
Response.Write( "<B>" + objPage.Message 2 + "</B>");
The question I am having is how can the "receiving page", in this case
"DisplayMessage s.aspx", determine what the class of the sending page is
during runtime? I would like to be able to have the
"DisplayMessage s.aspx" page accept messages from many different pages
but since I need to cast the Context.Handler object to the class of the
sending page it would seem that I would need to know the class name
ahead of time. Any suggestions?

Thanks!

Nov 19 '05 #1
3 1300
There's no [easy] way to know the type of a class unless you, well, know
what it is...

That's why we are blessed with inheritance and interfaces. Using these, you
might not know what the first page was exactly, but you know that it was of
type "BasePage"o r implemented "IMessenger " or whatever you call it. That
is, any page that will transfer to DisplayMessage should implement the
IMessageGenerat or interface which defines two properties, Message1 and
Message2...you can then do:

string message1 = ((IMessageGener ator)Context.Ha ndler).Message1 ;
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"mnet123" <mn*****@online .nospam> wrote in message
news:D8******** *************** ***********@mic rosoft.com...
I am using "Server.Transfe r()" to send data to an ASP.NET page that's
sole purpose is to display messages. I am using "Server.Transfe r since I
can set the contents of the message I want to display via the properties
of the page that is initiating the Server.Transfer () and also because
large amounts of data can be sent, such as a datagrid or other object.
Here is an example...
/* Sending Page (GenerateMessag e.aspx) */

private string mMsg1 = "This is the first message";
private string mMsg2 = "This is the second message";

public string Message1
{
Get {return mMsg1;}
}

public string Message2
{
Get {return mMsg2;}
}
Server.Transfer ("DisplayMessag *es.aspx");

/* Receiving Page (DisplayMessage s.aspx) */

GenerateMessage objPage = (GenerateMessag e)Context.Handl *er;
Response.Write( "<B>" + objPage.Message 1 + "</B>");
Response.Write( "<B>" + objPage.Message 2 + "</B>");
The question I am having is how can the "receiving page", in this case
"DisplayMessage s.aspx", determine what the class of the sending page is
during runtime? I would like to be able to have the
"DisplayMessage s.aspx" page accept messages from many different pages
but since I need to cast the Context.Handler object to the class of the
sending page it would seem that I would need to know the class name
ahead of time. Any suggestions?

Thanks!

Nov 19 '05 #2
Thanks for Karl's input.

Hi Mnet123,

Since the Context.Handler is a base HttpHandler reference, we can only use
GetType to get its type info dynamically and
can't use Explicit cast (we don't know the Type at compiled time in code).
For such scenario, in addition to Karl's suggestion, I think another
possible means is define a helper Class which has a certain helper function
take the Handler input paramter, and in that function, we use a

swtich(handler. GetType)
{
case xxx:
....
case yyy:
....
}

Thanks can somewhat workaround the problem here.
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3
Alternatively you could store the name of the sending class in the context
object before calling server transfer and then read it out on your message
page

jd

"Steven Cheng[MSFT]" wrote:
Thanks for Karl's input.

Hi Mnet123,

Since the Context.Handler is a base HttpHandler reference, we can only use
GetType to get its type info dynamically and
can't use Explicit cast (we don't know the Type at compiled time in code).
For such scenario, in addition to Karl's suggestion, I think another
possible means is define a helper Class which has a certain helper function
take the Handler input paramter, and in that function, we use a

swtich(handler. GetType)
{
case xxx:
....
case yyy:
....
}

Thanks can somewhat workaround the problem here.
Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #4

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

Similar topics

16
6201
by: Donjuan | last post by:
Hi all I have trouble with tracking whether my image file is loaded. i use DHTML to change my image. HERE is the code: <img name="someimage" src="1.jpg" onclick="document.all.someimage.src='someimage.jpg"> but how can i determine whether "someimage.jpg" is loaded? and can i get the download percent of a file? Thanks in advance
5
2353
by: mg | last post by:
Is there a simple way to determine the name & path of the Web page that calls a WebForm when the calling page is another type such as an html, jsp, or .do file.
5
3446
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
1851
by: jaYPee | last post by:
is there a way to know if the form is edited or not after calling addnew? Me.BindingContext(DsStudentCourse1, "Students").AddNew() because i got an error after closing the form. because in my form closing event i have a code to call the EndCurrentEdit to determine if the dataset has changes or not. here is my code in closing event Private Sub Students_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)...
3
11591
by: Developer in California | last post by:
I am working on developing a generic Web framework using Master Pages in ASP.NET 2.0. What I have done is created a PageRenderer class which has a public method which will retrieve the path of the content I want to execute based on the name of the asp:Content control. As shown in the code snippet below, to get the content I want to display, I call the GetContentPagePath public method in PageRenderer passing a string duplicating the value...
7
16947
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to write an helper method that will tell if the socket is connected or not , but it's not working good continue to tell me that the socket is connectedeven if the other party already call shutdown(both) + close , or , even if the other party close the...
6
14373
by: Jana | last post by:
Greetings Access Gurus! I am working on an app to send batch transactions to our bank, and the bank requires that we place an effective date on our files that is 'one business day in the future, excluding holidays and weekends.' I didn't want to build a table of holidays that would have to be continuously updated, so I searched high and low for a function that would tell me whether a given date was a holiday, to no avail. I did find an...
6
1334
by: Alexander Vasilevsky | last post by:
How do you determine (on the client, on the server) that the visitor leave the site? http://www.alvas.net - Audio tools for C# and VB.Net developers
3
1949
by: Tod Birdsall | last post by:
Hi, My boss has asked me to create a tool that can give us a list of stored procedure names that are being called from each of our app's web pages. This is an ASP.NET application that is rather large and about 5 years old. I am not here to debate the logic of the request. The structure of most the application is pretty standardized: We created a business/data layer that contains methods that have the names of the stored procedures to...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.