another Object reference not set to an instance of an object. prob

G

Guest

I'm a beginner with .NET so this is probably a very simple problem that will
be immediately obvious to someone hopefully. I'm using J#.NET

The following contains the code caused the error

Line 385: String link = "http://10.4.190.120/config/lconfig.aspx" ;
Line 386: GtLink.Redirect(link);
Line 387: //NLine.set_Text(Selection);

STACK TRACE

[NullReferenceException: Object reference not set to an instance of an
object.]
Config.Config.Update_Click(Object sender, EventArgs e) in
E:\Inetpub\wwwroot\Portal\Config\Config.aspx.jsl:386
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
+232

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +5
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint

Am I leaving something out or should I be initializing something firat. I
had the same error trying to get the server variables from the client but I
gave up on it eventually as I was able to work without the Host name though
it would add an extra element of security that I am looking for.

Thanks in adv for any help.

Dubh
 
J

Joakim Karlsson

Is GtLink a type or an object reference? That is, does the line

GtLink.Redirect(link)

mean 'call the static Redirect method defined by the GtLink class', or
does it mean 'call the Redirect method on the object referenced by the
GtLink variable'.

If it is the latter, the GtLink variable is probably not initialized,
otherwise we need a bit more info.

Regards,
Joakim
 
G

Guest

GtLink is defined here:

protected System.Web.HttpResponse GtLink;

Does that help?

Joakim Karlsson said:
Is GtLink a type or an object reference? That is, does the line

GtLink.Redirect(link)

mean 'call the static Redirect method defined by the GtLink class', or
does it mean 'call the Redirect method on the object referenced by the
GtLink variable'.

If it is the latter, the GtLink variable is probably not initialized,
otherwise we need a bit more info.

Regards,
Joakim
I'm a beginner with .NET so this is probably a very simple problem that will
be immediately obvious to someone hopefully. I'm using J#.NET

The following contains the code caused the error

Line 385: String link = "http://10.4.190.120/config/lconfig.aspx" ;
Line 386: GtLink.Redirect(link);
Line 387: //NLine.set_Text(Selection);

STACK TRACE

[NullReferenceException: Object reference not set to an instance of an
object.]
Config.Config.Update_Click(Object sender, EventArgs e) in
E:\Inetpub\wwwroot\Portal\Config\Config.aspx.jsl:386
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
+232

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +5
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint

Am I leaving something out or should I be initializing something firat. I
had the same error trying to get the server variables from the client but I
gave up on it eventually as I was able to work without the Host name though
it would add an extra element of security that I am looking for.

Thanks in adv for any help.

Dubh
 
J

Joakim Karlsson

Do you ever assign the GtLink variable to anything?

I suspect you don't.

Regards,
Joakim
GtLink is defined here:

protected System.Web.HttpResponse GtLink;

Does that help?

:

Is GtLink a type or an object reference? That is, does the line

GtLink.Redirect(link)

mean 'call the static Redirect method defined by the GtLink class', or
does it mean 'call the Redirect method on the object referenced by the
GtLink variable'.

If it is the latter, the GtLink variable is probably not initialized,
otherwise we need a bit more info.

Regards,
Joakim
I'm a beginner with .NET so this is probably a very simple problem that will
be immediately obvious to someone hopefully. I'm using J#.NET

The following contains the code caused the error

Line 385: String link = "http://10.4.190.120/config/lconfig.aspx" ;
Line 386: GtLink.Redirect(link);
Line 387: //NLine.set_Text(Selection);

STACK TRACE

[NullReferenceException: Object reference not set to an instance of an
object.]
Config.Config.Update_Click(Object sender, EventArgs e) in
E:\Inetpub\wwwroot\Portal\Config\Config.aspx.jsl:386
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
+232

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +5
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint

Am I leaving something out or should I be initializing something firat. I
had the same error trying to get the server variables from the client but I
gave up on it eventually as I was able to work without the Host name though
it would add an extra element of security that I am looking for.

Thanks in adv for any help.

Dubh
 
G

Guest

Is it not assigned to the System.Web.HttpResponse object ? Does it have to be
initialized first?

Joakim Karlsson said:
Do you ever assign the GtLink variable to anything?

I suspect you don't.

Regards,
Joakim
GtLink is defined here:

protected System.Web.HttpResponse GtLink;

Does that help?

:

Is GtLink a type or an object reference? That is, does the line

GtLink.Redirect(link)

mean 'call the static Redirect method defined by the GtLink class', or
does it mean 'call the Redirect method on the object referenced by the
GtLink variable'.

If it is the latter, the GtLink variable is probably not initialized,
otherwise we need a bit more info.

Regards,
Joakim

Dubh wrote:

I'm a beginner with .NET so this is probably a very simple problem that will
be immediately obvious to someone hopefully. I'm using J#.NET

The following contains the code caused the error

Line 385: String link = "http://10.4.190.120/config/lconfig.aspx" ;
Line 386: GtLink.Redirect(link);
Line 387: //NLine.set_Text(Selection);

STACK TRACE

[NullReferenceException: Object reference not set to an instance of an
object.]
Config.Config.Update_Click(Object sender, EventArgs e) in
E:\Inetpub\wwwroot\Portal\Config\Config.aspx.jsl:386
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
+232

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +5
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint

Am I leaving something out or should I be initializing something firat. I
had the same error trying to get the server variables from the client but I
gave up on it eventually as I was able to work without the Host name though
it would add an extra element of security that I am looking for.

Thanks in adv for any help.

Dubh
 
J

Jon Skeet [C# MVP]

Dubh said:
Is it not assigned to the System.Web.HttpResponse object ? Does it have to be
initialized first?

System.Web.HttpResponse is a type, not an object. You have to set the
variable's value in order for it to become non-null, yes.
 
G

Guest

Excuse my ignorance regarding terminology. I'm finding it a bit difficult
with the J#.NET stuff as it doesn't have as many examples or even
documentation as VB.NET or C*.NET. Could you give me a very quick example of
what I should be putting in.

Currently I am using the following lines

protected System.Web.HttpResponse GtLink;

String link = "http://10.4.190.120/config/lconfig.aspx" ;
GtLink.Redirect(link);

Couldn't I have just as easily used

protected System.Web.HttpResponse GtLink;
GtLink.Redirect("http://10.4.190.120/config/lconfig.aspx");

and still get the same error. What do I need to make GtLink non-null?
Also could this be why I was getting the same error when trying to get the
server variables using HttpRequest.get_UserHostAddress(). Should I be
initializing something there as well?

Thanks again for all your help.

Dubh
 
J

Jon Skeet [C# MVP]

Dubh said:
Excuse my ignorance regarding terminology. I'm finding it a bit difficult
with the J#.NET stuff as it doesn't have as many examples or even
documentation as VB.NET or C*.NET.

Indeed - although the problem is absolutely the same in any of the
languages.
Could you give me a very quick example of what I should be putting in.

I'm not an ASP.NET expect, but I'm sure there's the Response property
of some kind of context that you have access to.
Currently I am using the following lines

protected System.Web.HttpResponse GtLink;

String link = "http://10.4.190.120/config/lconfig.aspx" ;
GtLink.Redirect(link);

Couldn't I have just as easily used

protected System.Web.HttpResponse GtLink;
GtLink.Redirect("http://10.4.190.120/config/lconfig.aspx");

and still get the same error. What do I need to make GtLink non-null?

Because you're trying to call an instance method on it. As it is, the
runtime is basically saying "I don't know which response I'm trying to
redirect."
Also could this be why I was getting the same error when trying to get the
server variables using HttpRequest.get_UserHostAddress(). Should I be
initializing something there as well?

Yes - otherwise it doesn't know which request you're talking about.
 
G

Guest

Jon,

thanks for your help though to be honest I'm none the wiser if not even more
confused. I think I'll just start at the beginning with the JScript language
tour and slowly work my way back to where I'm stuck. I studied Basic and
Cobol but that was years ago and am only doing this to set up a netware
systems monitoring and admin website at work.
I'm not an ASP.NET expect, but I'm sure there's the Response property
of some kind of context that you have access to.

No idea what you mean by this! I have a drop-down list of a grouping of
servers and depending on what was selected I want to redirect the user to
administer or reconfigure it on a separate page. I don't want to use a
hyperlink as I need to send extra info so I'm using a standard button and
calling the code on the OnClick event.

main code ...

protected System.Web.HttpResponse GtLink;

.....more code

private void Update_Click (Object sender, System.EventArgs e)
{
.................some code
String link = "http://10.4.190.120/config/lconfig.aspx" ;
GtLink.Redirect(link);
..................some code
}

Take the following code as an example of an area with no issue.

main code ....
protected System.Web.UI.WebControls.TextBox NLine;

.....more code

Selection = DDList1.get_SelectedItem().get_Text(); //Get Line to be
configured DD
NLine.set_Text(Selection);

My textbox shows the item selected form the DDlist, yet I didn't do anything
to pre-initialize NLine. I expected that the same would apply to GtLink??
Because you're trying to call an instance method on it. As it is, the
runtime is basically saying "I don't know which response I'm trying to
redirect."

I assumed that what I was telling it to do was If this button is clicked
then this and that and open the following web page. Obviously it is not that
simple.
Yes - otherwise it doesn't know which request you're talking about.

Thanks

Dubh
 
G

Guest

Cor,

I know it looks simple but unfortunately it isn't. If I use that code I get
the following:

Name 'Response' is not defined in current context

I have this same problem with all the given examples. Even if I use the
simple expression: var string1 = "Hello"; , I get the following error:

Cannot find class 'var'

Dubh
 
G

Guest

I think the problem is that the examples are JScript as opposed to J#. Ia
there a difference?
 
C

Cor Ligthert

Hi Dubh,

JScript is absolute no J#. JScript comes from JavaScript a scripting
language created by AFAIK Netscape.

Cor
 
G

Guest

Which ties into what I was saying about examples earlier on. There are
practically no examples to speak of on MSDN. I'll have to keep digging.
Thanks anyway everyone.

Dubh
 

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

Top