Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / April 2004

Tip: Looking for answers? Try searching our database.

How to determine calling page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NewsMonkey - 28 Mar 2004 17:19 GMT
Hi Everyone,

 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("DisplayMessages.aspx");

/* Receiving Page (DisplayMessages.aspx) */

GenerateMessage objPage = (GenerateMessage)Context.Handler;
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!

- DerekTheGeek
DotNetJunkies User - 20 Apr 2004 19:46 GMT
I am having the same problem.  If you figure out (or have figured out) the answer to your question, please let me know

Please email at:

chadbryant5@pobox.com

---
Peter - 23 Apr 2004 20:36 GMT
I can think of two easy ways to handle this problem.  

1.

Send a message via the QueryString in your Server.Transfer call:
Server.Transfer("SomePage.aspx?s=1");

And in the page you transferred to:
   
if (Request.QueryString["s"] != null)
{
  switch(Request.QueryString["s"])
  {
     case "1":
        this.lblMessage1.Text =
((TestSender_1)Context.Handler).SenderName;
        this.lblMessage2.Text =
((TestSender_1)Context.Handler).Message;
        break;
     case "2":
        this.lblMessage1.Text =
((TestSender_2)Context.Handler).SenderName;
        this.lblMessage2.Text =
((TestSender_2)Context.Handler).Message;
        break;
     default:
        this.lblMessage1.Text = "No Sender";
        this.lblMessage1.Text = "No Message";
        break;
  }
}

Where lblMessage1 & lblMessage2 are labels on SomePage.aspx and
SenderName and Message are public properties on the sending pages
(TestSender_1 & TestSender_2).

2.  

If you are going to be transferring from many pages and the properties
are going to be the same you can implement an interface on the page
that does the Server.Transfer.  (I'd choose the QueryString
implementation over this however.)

public class SenderPage : System.Web.UI.Page, IMessage {}

In the case of this example the interface IMessage will contain
SenderName and Message and the implementing pages contain the code for
such.

The code on the page you transfer to will should look similar to this:

this.lblMessage1.Text = ((IMessage)Context.Handler).SenderName;
this.lblMessage2.Text = ((IMessage)Context.Handler).Message;

Well, hope that helps.
-Peter

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.