Saturday, March 24, 2012

Object reference not set to an instance of an object

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?On May 27, 3:38 pm, "dancer" <dan...@.microsoft.com> wrote:
> 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>
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
"Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
news:1180275653.092361.233360@.h2g2000hsg.googlegroups.com...
> On May 27, 3:38 pm, "dancer" <dan...@.microsoft.com> wrote:
> 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>
>
On May 27, 4:52 pm, "dancer" <dan...@.microsoft.com> wrote:
> 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.
>
Is it the same as in your previous post?
http://groups.google.com/group/micr...45034592e203207
add a RequiredFieldValidator for the EmpCaution
otherwise send me a code, I will check it, no problem :-)
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!
"Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
news:1180278453.787842.50280@.q66g2000hsg.googlegroups.com...
> On May 27, 4:52 pm, "dancer" <dan...@.microsoft.com> wrote:
> Is it the same as in your previous post?
> http://groups.google.com/group/micr...45034592e203207
> add a RequiredFieldValidator for the EmpCaution
> otherwise send me a code, I will check it, no problem :-)
>
On May 27, 5:31 pm, "dancer" <dan...@.microsoft.com> wrote:
> 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 selecti
on
> 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
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>
"Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
news:1180286369.120549.28460@.w5g2000hsg.googlegroups.com...
> On May 27, 5:31 pm, "dancer" <dan...@.microsoft.com> wrote:
> 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
>
On May 27, 9:36 pm, "dancer" <dan...@.microsoft.com> wrote:
> 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.
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.
"Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
news:1180286369.120549.28460@.w5g2000hsg.googlegroups.com...
> On May 27, 5:31 pm, "dancer" <dan...@.microsoft.com> wrote:
> 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
>
On May 27, 10:03 pm, "dancer" <dan...@.microsoft.com> wrote:
> I don't want the user to be able to check both employee and non-employee o
r
> only one. A RequiredField Validator won't work here. How can I ensure th
at
> the user checks 1 or both?
A RadioButton (RadioButtonList) will give you a single value selection.

0 comments:

Post a Comment