Request object not working

D

Dave

Hi,

I have a weird problem.

I have a user control, included in a page. This UC does
authentication and tracking.

I developed the code in the page_load event and it works
OK. I then moved it into its own event, CheckUser() and
it stopped working.

I added "sender, e" into the parameters, but it still
don't work.

The CheckUser is being called directly from the parent
page.

It appears the Request object doesn't want to work, and I
don't know why. The first line it stops at uses
Request.UserHostAddress.ToString(). If I skip that, it
fails at the next use of the request object.

Now, if I put CheckUser(sender, e) into the UC page_load
event, then it will work, but it isn't working from the
parent page.

I am obviously missing something. Can anyone help?

Thanks.
Dave Colliver.
http://www.AshfieldFOCUS.com
 
J

John Saunders

Dave said:
Hi,

I have a weird problem.

I have a user control, included in a page. This UC does
authentication and tracking.

I developed the code in the page_load event and it works
OK. I then moved it into its own event, CheckUser() and
it stopped working.

What do you mean, "it stopped working"? Details, please?

John Saunders
 
D

Dave

An example...

my ASCX.CS

private void Page_Load(object sender, System.EventArgs e)
{
//CheckUser(sender, e);
}

public void CheckUser(object sender, System.EventArgs e)
{
Response.Write
(Request.UserHostAddress.ToString());
}


My ASPX.CS

private void Page_Load(object sender, System.EventArgs e)
{
MyUserControl.UserTracking
userTrack = new MyUserControl.UserTracking();
userTrack.CheckUser(sender, e);
}


This would compile but result in a runtime error. Object
reference not set to an instance of an object, on the
line with the Request statement. (I changed the statement
to something else, and it went past it.)

Initially, the request.user... line was in the UCs
page_load and worked OK.

It also works OK if I call the CheckUser from within the
UCs page_load, but it fails if I call it from the
page_load of the host page.

What the UC is actually doing is to save into a database
info about the user and the request, then set a property
if the user is OK. (You responded to another question of
mine earlier in the week, which I think has more detail
of what I am doing.)

Thanks for your assistance.

Best regards,
Dave Colliver.
http://www.PlymouthFOCUS.com
 
J

John Saunders

Dave said:
An example...

my ASCX.CS

private void Page_Load(object sender, System.EventArgs e)
{
//CheckUser(sender, e);
}

public void CheckUser(object sender, System.EventArgs e)
{
Response.Write
(Request.UserHostAddress.ToString());
}


My ASPX.CS

private void Page_Load(object sender, System.EventArgs e)
{
MyUserControl.UserTracking
userTrack = new MyUserControl.UserTracking();
userTrack.CheckUser(sender, e);
}

You can't load a user control like that. You need to use LoadControl:

userTrack = (MyUserControl.UserTracking) LoadControl("whatever.ascx");


John Saunders
 
D

Dave

even if the control has been dragged onto the aspx page?

I will give your way a go, but I am assuming that the
control doesn't even need to be added to the aspx.

Best regards,
Dave Colliver.
http://www.OxfordFOCUS.com
 
J

John Saunders

Dave said:
even if the control has been dragged onto the aspx page?

I will give your way a go, but I am assuming that the
control doesn't even need to be added to the aspx.

If the control is already there, then why are you creating a new instance
(with "new"?)

John Saunders

 
D

Dave

Doh!!!

Thanks for your help. Even though this was not the
problem, it led me to the solution.

I had dragged the UC onto the page but it did not appear
in the list of objects in the cs for some reason.
Therefore, I added it myself, as "Object was not set to
an instance of an object" just to try and get it to work.

However, I added it with a new name which was different
to the UC on the page.

Best regards,
Dave Colliver.
http://www.GreatYarmouthFOCUS.com
 

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

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top