Wednesday, March 21, 2012

Passing a page to a public class

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

Danyour 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 :-)
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......!

:o)

"John Rivers" wrote:

> 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 :-)
>
No matter, sorted that one! :o)

"dhnriverside" wrote:

> 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......!
> :o)
> "John Rivers" wrote:
> > 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 :-)

0 comments:

Post a Comment