Passing a page to a public class

G

Guest

Hi guys

I'm trying to implement an external class (.cs) for popping a window and
doing various bits and peices. I want to pass to the overloaded constructor a
reference to the page that called the class, so that the class can add some
javascript to the page.

Here's my globals and constructor...

public string e;
public System.Web.UI.Page _sender;

public ACR(string e, System.Web.UI.Page sender)
{
_errorcode = e;
_sender = sender;

DoACR();
}

here's the code for the DoACR() function...

public void DoACR()
{
string cs;
cs = "<script language=\"Javascript\">\n";
cs += "window.open('acr.aspx?c=" + _errorcode + "&p=" +
_sender.Request.ServerVariables["HTTP_URL"].ToString() + "', '_blank',
'width=" +
ConfigurationSettings.AppSettings.Get("System_ReportBug_WindowWidth") + ",
height=" +
ConfigurationSettings.AppSettings.Get("System_ReportBug_WindowHeight") +
",channelmode=0,directories=0,fullscreen=0,location=0,resizable=0,scrollbars=0,status=0,toolbar=0');";
cs += "window.close();\n";
cs += "</script>";
if(!_sender.IsStartupScriptRegistered("close"))
_sender.RegisterStartupScript("close", cs);
}

and from my Page_Load of my page, I'm calling it thus...

ACR crash = new ACR("0x00", this);

I'm getting a "object reference not set to an object" error on the line in
DoACR() that calls _server.Request.ServerVariables["HTTP_URL"].ToString();

How is that happening? As I'm callling my class from Page_Load, I assume
that "this" has been defined as the Page?

Any thoughts appreciated...

Cheers



Dan
 
J

John Rivers

your problem is here:

_server.Request.ServerVariable­s["HTTP_URL"].ToString()

dump the ".ToString()"

it is a "string" already

cs += "blah" + _server.Request.ServerVariable­s["HTTP_URL"] +
"moreblah";

will work just fine

you owe me a mars bar :)
 
G

Guest

Cheers John - I do indeed owe you a Mars bar! In fact, you can have a King
Size Mars bar if you can tell me why ServerVariables["HTTP_URL"] is
empty........!

:eek:)
 
G

Guest

No matter, sorted that one! :eek:)

dhnriverside said:
Cheers John - I do indeed owe you a Mars bar! In fact, you can have a King
Size Mars bar if you can tell me why ServerVariables["HTTP_URL"] is
empty........!

:eek:)

John Rivers said:
your problem is here:

_server.Request.ServerVariable­s["HTTP_URL"].ToString()

dump the ".ToString()"

it is a "string" already

cs += "blah" + _server.Request.ServerVariable­s["HTTP_URL"] +
"moreblah";

will work just fine

you owe me a mars bar :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top