Object reference not set to an instance of an object

D

dancer

Using VB.net and ASP.net

At runtime I receive the error that MANY people receive who are using much
more complicated code than mine.

"Object reference not set to an instance of an object. "

I know WHY it's happening. It is when a selection is not made to a
RadioButtonList, so the item is = to nothing.

I have a RequiredFieldValidator, but the runtime error obviously shows
before the validator can act.

The advice given on this error is that "You are trying to use a reference
variable whose value is Nothing"

How can I make the RequiredFieldValidator work BEFORE this runtime error
occurs?
 
G

Guest

Using VB.net and ASP.net

At runtime I receive the error that MANY people receive who are using much
more complicated code than mine.

"Object reference not set to an instance of an object. "

I know WHY it's happening. It is when a selection is not made to a
RadioButtonList, so the item is = to nothing.

I have a RequiredFieldValidator, but the runtime error obviously shows
before the validator can act.

The advice given on this error is that "You are trying to use a reference
variable whose value is Nothing"

How can I make the RequiredFieldValidator work BEFORE this runtime error
occurs?

What's your code for validator? Have you set the ControlToValidate?

some code that should work

<asp:RadioButtonList ID="ccType" Font-Names="Arial"
RepeatLayout="Flow" runat="server">
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
</asp:RadioButtonList>

<asp:RequiredFieldValidator ID="ccTypeReqVal"
ControlToValidate="ccType" ErrorMessage="Card Type. "
Display="Static" InitialValue="" Font-Names="Verdana" Font-Size="12"
runat="server">
*
</asp:RequiredFieldValidator>
 
D

dancer

My validator code is ok. I copied it to another file, and it worked fine.
Are you game to look at the rest of my code? If so, I will copy it here.

Thanks
 
D

dancer

Yes. I just looked at your reply there:

"I think, you forgot to add a RequiredFieldValidator for the EmpCaution
list "

I don't have a RequiredFieldValidator for that or some others, because I'm
limiting my testing. The less code I have, the less to confuse me. I
always enter a selection for those radiobutton lists when testing the
EmpTrain list. I get the runtime error ONLY when I don't enter a selection
for those OR for the EmpTrain list [even though the EmpTrain list has a
validator]

Did that paragraph make any sense?

Thank you. If you can find any reason for the error, I will be eternally
grateful!
 
G

Guest

I don't have a RequiredFieldValidator for that or some others, because I'm
limiting my testing. The less code I have, the less to confuse me. I
always enter a selection for those radiobutton lists when testing the
EmpTrain list. I get the runtime error ONLY when I don't enter a selection
for those OR for the EmpTrain list [even though the EmpTrain list has a
validator]

Using ClientTarget="downlevel" you render old browsers-compatible code
without javascript validation and any other client-side server control
functionality. Get rid of the ClientTarget and validation will work
again.

ASP.NET Web Server Controls and Browser Capabilities
http://msdn2.microsoft.com/en-us/library/x3k2ssx2.aspx
 
D

dancer

WHAT A RELIEF!!!
Thank you Alexey!!! It works on my local computer, BUT when I download
it to my server, it won't even let me see the page. I get this message:

Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable
on remote machines, please create a <customErrors> tag within a "web.config"
configuration file located in the root directory of the current web
application. This <customErrors> tag should then have its "mode" attribute
set to "Off".

<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>

Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirect" attribute of the application's
<customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>




Anon User said:
I don't have a RequiredFieldValidator for that or some others, because
I'm
limiting my testing. The less code I have, the less to confuse me. I
always enter a selection for those radiobutton lists when testing the
EmpTrain list. I get the runtime error ONLY when I don't enter a
selection
for those OR for the EmpTrain list [even though the EmpTrain list has a
validator]

Using ClientTarget="downlevel" you render old browsers-compatible code
without javascript validation and any other client-side server control
functionality. Get rid of the ClientTarget and validation will work
again.

ASP.NET Web Server Controls and Browser Capabilities
http://msdn2.microsoft.com/en-us/library/x3k2ssx2.aspx
 
G

Guest

WHAT A RELIEF!!!
Thank you Alexey!!! It works on my local computer,

Great, glad you fixed it.

BUT when I download
it to my server, it won't even let me see the page. I get this message:

Go to the web.config file on your server and change customErrors to
Off

<customErrors mode="Off"/>

You should see a real error message then.
 
D

dancer

ONE OTHER THING WITH THE FOLLOWING:
If Checkemp.Checked Then

Empornon = "Employee"

ElseIf Checknon.checked Then

empornon= "Non-Employee"

Else Empornon = ""

End If

-------------------------------------------------

I don't want the user to be able to check both employee and non-employee or
only one. A RequiredField Validator won't work here. How can I ensure that
the user checks 1 or both?

If neither are checked I get this message: "Input string was not in a
correct format"

Thank you again.




Anon User said:
I don't have a RequiredFieldValidator for that or some others, because
I'm
limiting my testing. The less code I have, the less to confuse me. I
always enter a selection for those radiobutton lists when testing the
EmpTrain list. I get the runtime error ONLY when I don't enter a
selection
for those OR for the EmpTrain list [even though the EmpTrain list has a
validator]

Using ClientTarget="downlevel" you render old browsers-compatible code
without javascript validation and any other client-side server control
functionality. Get rid of the ClientTarget and validation will work
again.

ASP.NET Web Server Controls and Browser Capabilities
http://msdn2.microsoft.com/en-us/library/x3k2ssx2.aspx
 
G

Guest

I don't want the user to be able to check both employee and non-employee or
only one. A RequiredField Validator won't work here. How can I ensure that
the user checks 1 or both?

A RadioButton (RadioButtonList) will give you a single value selection.
 
D

dancer

But I want to be sure he checks one or both. I understand that you can't
use a validator with a radio button.
Also I get an error if it is not checked.

??
 
G

Guest

But I want to be sure he checks one or both. I understand that you can't
use a validator with a radio button.
Also I get an error if it is not checked.

??

You said "I ***don't*** want the user to be able to check both
employee and non-employee"
But I want to be sure he checks one or both.

So, is it possible to be an Employee and Non-Employee in the same
time?
 
D

dancer

I think I was taking a nap when I wrote that. I MEANT to say I WANT the user
to check either one or both.
It is possible that 2 people are hurt in the same accident - one an employee
and the other a non-employee.
 
D

dancer

OOPS - There's a flaw in my if- then logic. The variable "Empornon" cannot
be equal to both.
 
D

dancer

What is wrong with my logic here? It returns "employee" if I check both.

If Checkemp.Checked AndAlso Checknon.checked Then

Empornon = "both"

ElseIf Checkemp.Checked Then

Empornon = "Employee"

ElseIf Checknon.checked Then

empornon= "Non-Employee"

Else Empornon = ""

End If
 
G

Guest

What is wrong with my logic here? It returns "employee" if I check both.

The code looks correct. Try to check the values before

Response.Write(Checkemp.Checked)
Response.Write(Checknon.Checked)
 
D

dancer

My logic is working.
Now, how do I make sure the user checks one or other or both?
If I validate each text box it will make him answer both, even if it's only
one.

Thanks
 
G

Guest

My logic is working.
Now, how do I make sure the user checks one or other or both?
If I validate each text box it will make him answer both, even if it's only
one.

If you have a question regarding code, you have to send that code.

I don't see your validation rule, how can I answer? :)
 
D

dancer

I don't have code for that yet. It is a question of concept. Is there a
control to verify that if one check box is not checked, then the other is?

Thank you
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top