473,320 Members | 2,147 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,320 software developers and data experts.

Determine calling page

I am using "Server.Transfer()" to send data to an ASP.NET page that's
sole purpose is to display messages. I am using "Server.Transfer 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 (GenerateMessage.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 (DisplayMessages.aspx) */

GenerateMessage objPage = (GenerateMessage)Context.HandlÂ*er;
Response.Write("<B>" + objPage.Message1 + "</B>");
Response.Write("<B>" + objPage.Message2 + "</B>");
The question I am having is how can the "receiving page", in this case
"DisplayMessages.aspx", determine what the class of the sending page is
during runtime? I would like to be able to have the
"DisplayMessages.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 1255
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"or implemented "IMessenger" or whatever you call it. That
is, any page that will transfer to DisplayMessage should implement the
IMessageGenerator interface which defines two properties, Message1 and
Message2...you can then do:

string message1 = ((IMessageGenerator)Context.Handler).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**********************************@microsof t.com...
I am using "Server.Transfer()" to send data to an ASP.NET page that's
sole purpose is to display messages. I am using "Server.Transfer 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 (GenerateMessage.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 (DisplayMessages.aspx) */

GenerateMessage objPage = (GenerateMessage)Context.Handl*er;
Response.Write("<B>" + objPage.Message1 + "</B>");
Response.Write("<B>" + objPage.Message2 + "</B>");
The question I am having is how can the "receiving page", in this case
"DisplayMessages.aspx", determine what the class of the sending page is
during runtime? I would like to be able to have the
"DisplayMessages.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
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"...
5
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
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...
3
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...
3
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...
7
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...
6
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,...
6
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
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.