473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error Message

I get this error if an item in a radiobutton list is not chosen when filling
in a form..

I added a RequiredFieldValidator, but I still get the message.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
May 25 '07 #1
4 2014
Hello dancer,

Do u know the line number where the error was arised? (should be in the stack
trace details)
It would be more usefull if you provide the code where is exection thrown

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

dI get this error if an item in a radiobutton list is not chosen when
dfilling in a form..
d>
dI added a RequiredFieldValidator, but I still get the message.
dObject reference not set to an instance of an object.
dDescription: An unhandled exception occurred during the execution of
dthe
dcurrent web request. Please review the stack trace for more
dinformation
dabout the error and where it originated in the code.
dException Details: System.NullReferenceException: Object reference
dnot set to an instance of an object.
d>
May 25 '07 #2

Is this helpful?
Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
ASP.juan_radio30_aspx.btnSendMail_OnClick(Object Source, EventArgs E)
+453
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
+107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

Here is my code:

<%@ Page Language="VB" ClientTarget="downlevel" %>

<%@ Import Namespace="System.Web.Mail" %>

<script language="VB" runat="server">

Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
Dim TheLocation As String = Location.Text

Dim TheDate As String = DateofAccident.Text

Dim TheWho As String = Who.Text

Dim Empornon As String

Dim TheCheckemp As String = checkemp.Text

Dim TheChecknon As String = Checknon.Text

Dim TheCheckpremisesyes As String = checkpremisesyes.Text

Dim TheCheckpremisesno As String = Checkpremisesno.Text

Dim Premises As String

Dim TheCheckJobsiteYes As String = checkjobsiteyes.text

Dim ThecheckJobsiteNo As String = checkjobsiteno.text

Dim Jobsite As String

Dim TheTimeAM As String = am.Text

Dim TheTimePM As String = pm.Text

Dim TheTime As String

Dim TheHireDate As String = Hiredate.Text

Dim TheJobTitle As String = occupation.Text

Dim Tenure As String = lengthofjob.Text

Dim TheOperation As String = operation.Text

Dim TheOperationNew As String

Dim TheHow As String = how.text

Dim TheHowNew As String

Dim TheNature As String = nature.Text

Dim TheNatureNew As String

Dim TheIndicate As String = Indicate.Text

Dim TheAction As String = action.Text

Dim TheActionNew As String

Dim Training As String = EmpTrain.SelectedItem.Text

Dim TheCaution as string=EmpCaution.SelectedItem.Text

Dim TheReport as String = EmpReport.SelectedItem.Text

Dim TheModifiedDuty As String = ModifiedDuty.SelectedItem.Text

Dim TheSubmitter As String = Submitter.Text

Dim TheToday As String = Today.Text

Dim myMessage As New MailMessage

Dim myMail As SmtpMail

Dim strEmail As String

Dim UserMessage As String

Dim TheGetOther As String = GetOther.Text
If Checkemp.Checked Then

Empornon = "Employee"

ElseIf Checknon.checked Then

empornon= "Non-Employee"

Else Empornon = ""

Writeline(empornon)

End If
If Checkpremisesyes.Checked Then

Premises = "Yes"

ElseIf Checkpremisesno.Checked Then

Premises = "No"

Else Premises = ""

End If

If CheckJobSiteYes.Checked Then

Jobsite = "Yes"

ElseIf CheckJobsiteNo.checked Then

Jobsite = "No"

Else Jobsite = ""

End If

If TheTimeAm <"" Then

TheTime = TheTimeAm & " AM"

ElseIf TheTimePM <"" Then

TheTime = TheTimePM & " PM"

Else TheTime = ""

End If

TheActionNew = TheAction.Replace(vbCrLf,"<br />")

TheNatureNew = TheNature.Replace(vbCrLf,"<br />")

TheHowNew = TheHow.Replace(vbCrLf,"<br />")

TheOperationNew = TheOperation.Replace(vbCrLf,"<br />")
Dim s As String

Dim i As Int32

For i = 0 to Indicate.Items.Count-1

If Indicate.Items(i).Selected Then

s= s & Indicate.Items(i).Text & "<br>"

End If

Next

If TheGetOther <"" Then

TheGetOther = "Other: " & TheGetOther

End If
If Page.IsValid() Then

'strEmail = txtEmail.Text

'Location = Location.Text

myMessage.From = "xx********@xxxxxxxxx.com"

' myMessage.To = strEmail

MyMessage.To = "xx**********@xxxxxxxxxx.com"

myMessage.Subject = "Accident Form (HTML)"

' This is the magic line. Without this the message will just appear

' as plain HTML and won't be rendered by the recipient's email client.

' It'd be as if they did "View Source" on a web page.

MyMessage.BodyFormat = MailFormat.Html

myMessage.Body = "<h2>Wheeler's Accident Investigation Form</h2>" & vbCrLf _

& " <p>" & vbCrLf _

& "<html><body<table width = ""750"" bgcolor=""#E9EDF4"" height=""25""
border=""1"" cellpadding=""3"" fontface=""Verdana"" Size=""2"">" & vbCrLf _

& "<tdLocation where accident occurred: " & "<br>" & Thelocation & "<br>"
& "</td>" & vbCrLf _

& "<tdEmployer's Premises? " & premises & "<br>" & vbCrLf _

& " Job Site? " & Jobsite & "<br>" & "</td>" & vbCrLf _

& "<tdDate of accident: " & TheDate & "<br>" & "</td>" & vbCrLf _

& "<tr><tdWho was injured: " & Thewho & "<br>" & "</td>" & vbCrLf _

& "<tdEmployee or non-employee?" & "<br>" & empornon & "<br>" & "</td>" &
vbCrLf _

& "<tdTime of accident: " & TheTime & "<br>" & "</td>" & "</tr>" & vbCrLf
_

& "<tdDate of Hire: " & TheHireDate & "<br>" & "</td>" & vbCrLf _

& "<tdJob Title: " & TheJobTitle & "<br>" & "</td>" & vbCrLf _

& "<tdHow long has employee worked at job where injury occurred? " &
Tenure & "<br>" & "</td>" & "</tr>" & vbCrLf _

& "<tr<td colspan=""3""What was employee doing when injury occurred? " &
TheOperation & "<br>" & "</td></tr>" & vbCrLf _

& "<tr<td colspan=""3""How did the injury occur? " & TheHowNew & "<br>"
& "</td></tr>" & vbCrLf _

& "<tr<td colspan=""3""Nature and extent injury and property damaged: "
& TheNatureNew & "<br>" & "</td></tr>" & vbCrLf _

& "<tr<td colspan=""3""PLEASE INDICATE ALL WHICH CONTRIBUTED TO THE
INJURY: " & "<BR>" & S & "</TD></TR>" & vbCrLf _

& "<tr<td colspan=""3""" & TheGetOther & "</td></tr>" & vbCrLf _

& "<tr<td colspan=""3""Supervisor's corrective action to ensure this
type of accident does not recur: " & TheActionNew & "<br>" & vbCrLf _

& "<tr<td colspan=""3""Was employee trained in the appropriate use of
Personal Protective Equipment/Proper safety procedures? " & Training &
vbCrLf _

& "<br>" & "</td></tr>" & vbCrLf _

& "<tr><td colspan=""3""Was employee cautioned for failure to use Personal
Protective Equipment/Proper safety procedures? " & TheCaution &"</tr></td>"
& vbCrLf _

& "<tr<tdDid employee promptly report the injury? " & TheReport &
"</td>" & vbCrLf _

& "<tdIs there modified duty available? " & TheModifiedduty & "</td></tr>"
& vbCrLf _

& "<tr<tdPerson submitting this form: " & "<br>" & theSubmitter &
"</td>" & vbCrLf _

& "<tdDate: " & Thetoday & vbCrLf _

& "</td><tr></table</body>"

' Doesn't have to be local... just enter your

' SMTP server's name or ip address!

myMail.SmtpServer = ""

myMail.Send(myMessage)

frmEmail.Visible = False

UserMessage = "Has Been Sent."

'lblUserMessage.Text = "Place of accident " & Thelocation

End If

End Sub

</script>

<html>

<head>

<title>ASP.NET Email (HTML Format) Sample</title>

</head>

<body>
<table width="750" bgcolor="#E9EDF4" table border="1" cellpadding="3">

<h3><center><font face="Verdana">Wheeler's Accident Investigation
Form</font></center></h3>

<form method="post" id="frmEmail" runat="server">

<%--asp:TextBox id="txtEmail" size="30" runat="server" /--%>
<%--asp:RegularExpressionValidator runat="server"

id="validEmailRegExp" ControlToValidate="txtEmail"

ValidationExpression="^[\w-]+(\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$"

errormessage="Please enter a valid email address."

Display="Dynamic" /--%>


<%--__________________________________________________ __________________________--%>

<%--ROW 1--%>
<td width="245" valign="top">
<font face="Verdana" Size="2">

Location where accident occurred: <asp:textbox id="Location" runat=server
columns="25"/>

<asp:RequiredFieldValidator

ControlToValidate="Location"

Text="The location field is required"

runat="server"/>

</td>

<td align="right" valign="top" width="225">
<font face="Verdana" Size="2">Employer's Premises

<asp:CheckBox id=Checkpremisesyes Text="yes" runat="server" />

<asp:CheckBox id=Checkpremisesno Text="no" runat="server" />

<br>
Job site

<asp:CheckBox id=Checkjobsiteyes Text="yes" runat="server" />

<asp:CheckBox id=Checkjobsiteno Text="no" runat="server" />
</td>

<td>

<font face="Verdana" Size="2">Date of accident</font><br>

<asp:textbox id="DateofAccident" runat=server Width="100"/>
</td>

<%--__________________________________________________ __________________________--%>

<%--ROW 2--%>
<tr<td>

<font face="Verdana" Size="2">Who was injured?</font><br>

<asp:textbox id="Who" runat=server columns="25"/>

</td>

<td align= "left">

<font face="Verdana" Size="2">Employee <asp:CheckBox id=Checkemp
runat="server" />

<br>

Non-employee <asp:CheckBox id="Checknon" runat="server" />
</td>

<td align="right"><font face="Verdana" Size="2">

Time of accident a.m. <asp:textbox columns="6" id="am" runat=server />

<brp.m. <asp:textbox id="pm" runat=server columns="6"/>

</TD>

<%--__________________________________________________ __________________________--%>

<%--ROW 3--%>

<tr>

<td>

<font face="Verdana" Size="2">Date of Hire <br<asp:textbox id="Hiredate"
runat=server/>

</td>

<td>

<font face="Verdana" Size="2">Job Title or Occupation <br><asp:textbox
id="occupation" runat=server columns="25"/>

</td>

<td<font face="Verdana" Size="2">How long has employee worked at job where
injury occurred?<br><asp:textbox id="lengthofjob" runat=server/>

</td>

</Table>

<%--__________________________________________________ __________________________--%>

<%--Row 4--%>

<table width="750" bgcolor="#E9EDF4" table border="1" cellpadding="3">

<tr>

<td>

<p>

<font face="Verdana" Size="2">What was employee doing when injury occurred?

What machine or tool was being used? What type of operation?<br>

<asp:textbox TextMode= "Multiline" Rows= "5" columns= "80"

id="operation" runat=server width="730" height="40"/>

</td>

</tr>

<%--__________________________________________________ __________________________--%>

<%--Row 5--%>

<td<font face="Verdana" Size="2">How did injury occur? List all objects
and substances involved.<br>

<asp:textbox TextMode="MultiLine" Rows="5" columns= "80" id="How"
runat=server/>

</td>

</tr>

<%--__________________________________________________ __________________________--%>

<%--Row 6--%>

<tr>

<td><font face="Verdana" Size="2"Nature and extent of injury and property
damaged (be specific)

<asp:textbox TextMode="MultiLine" Rows="2" columns= "80" id="nature"
runat=server/>

</td>

</tr>

<%--__________________________________________________ __________________________--%>

<%--Row 7--%>

<tr>

<td><font face="Verdana" Size="2" type = "strong"PLEASE INDICATE ALL OF
THE FOLLOWING WHICH CONTRIBUTED TO THE INJURY:

<asp:CheckBoxList id=Indicate runat="server">

<asp:ListItem style<font face="Verdana" Size="2">Improper
instruction</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Lack of training or
skill</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Operating without
authority</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Horseplay</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Physical or mental
impairment</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Failure to
secure</asp:ListItem>

<asp:ListItem style<font face="Verdana" Size="2">Failure to
lockout</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Unsafe position</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Improper dress</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Improper protective
equipment</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Unsafe equipment</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Poor
housekeeping</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Unsafe arrangement or
process</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Poor ventilation</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Improper
guarding</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Improper
maintenance</asp:ListItem>

<asp:ListItem<font face="Verdana" Size="2">Inoperative safety
device</asp:ListItem>
</asp:CheckBoxListOther <asp:TextBox columns = "50" id="GetOther"
runat=server/>

</td>

</tr>

<%--__________________________________________________ __________________________--%>

<%--Row 8--%>

<tr>

<td colspan= "3"><font face="Verdana" Size="2"Supervisor's corrective
action to ensure this type of accident does not recur:

<asp:TextBox TextMode="MultiLine" Rows="5" columns= "80" id=action
runat="server"/>

<br>

</tr>

</td>

<%--__________________________________________________ __________________________--%>

<%--Row 9--%>

<tr>

<td<font face="Verdana" Size="2">Was employee trained in the appropriate
use of Personal Protective Equipment/Proper safety procedures?

<br>

<asp:RadioButtonList font-name="verdana" font-size="10 pt" id=EmpTrain
runat="server">

<asp:ListItem>Yes</asp:ListItem>

<asp:ListItem>No</asp:ListItem>

</asp:RadioButtonList>

<asp:RequiredFieldValidator

ControlToValidate="EmpTrain"

InitialValue=""

Text="You need to select yes or no"

runat="server"/>

</td>

</tr>

<%--__________________________________________________ __________________________--%>

<%--Row 10--%>

<tr>

<td<font face="Verdana" Size="2">

Was employee cautioned for failure to use Personal Protective
Equipment/Proper safety procedures? <br>

<asp:RadioButtonList font-name="verdana" font-size="10 pt" id=EmpCaution
runat="server">

<asp:ListItem>Yes</asp:ListItem>

<asp:ListItem>No</asp:ListItem>

</asp:RadioButtonList>
</td>

</tr>

<%--__________________________________________________ __________________________--%>

<%--Row 11--%>

<tr>

<td<font face="Verdana" Size="2">

Did employee promptly report the injury?

<asp:RadioButtonList font-name="verdana" font-size="10 pt" id=EmpReport
runat="server">

<asp:ListItem>Yes</asp:ListItem>

<asp:ListItem>No</asp:ListItem>

</asp:RadioButtonList>
</td>

</tr>

<%--__________________________________________________ __________________________--%>

<%--Row 12--%>

<tr>

<td<font face="Verdana" Size="2">Is there modified duty available?

<asp:RadioButtonList font-name="verdana" font-size="10 pt" id=ModifiedDuty
runat="server">

<asp:ListItem>Yes</asp:ListItem>

<asp:ListItem>No</asp:ListItem>

</asp:RadioButtonList>
</td>

</tr>

<%--__________________________________________________ __________________________--%>

<%--Row 12--%>

</table>

<table width="750" bgcolor="#E9EDF4" table border="1" cellpadding="3">

<td width="400"><font face="Verdana" Size="2"Name of person submitting
this form:

<asp:textbox id="Submitter" runat=server columns="40"/</td>
<td<font face="Verdana" Size="2">Today's Date: <asp:textbox id="Today"
runat=server columns="10"/>

</td>

</tr>

<tr>

<td>

<asp:Button id="btnSendMail" text="Submit" OnClick="btnSendMail_OnClick"
runat="server" />

</td>

</tr>

<asp:ValidationSummary

HeaderText="You must enter a value in the following fields:"

DisplayMode="BulletList"

EnableClientScript="true"

ShowMessageBox = "true"

runat="server"/>

</form>

</body>

</html>
"Michael Nemtsev" <ne*****@msn.comwrote in message
news:a2***************************@msnews.microsof t.com...
Hello dancer,

Do u know the line number where the error was arised? (should be in the
stack trace details)
It would be more usefull if you provide the code where is exection thrown

---
WBR, Michael Nemtsev [.NET/C# MVP]. My blog:
http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

dI get this error if an item in a radiobutton list is not chosen when
dfilling in a form..
ddI added a RequiredFieldValidator, but I still get the message.
dObject reference not set to an instance of an object.
dDescription: An unhandled exception occurred during the execution of
dthe
dcurrent web request. Please review the stack trace for more
dinformation
dabout the error and where it originated in the code.
dException Details: System.NullReferenceException: Object reference
dnot set to an instance of an object.
d>

May 25 '07 #3
On May 25, 11:08 pm, "dancer" <dan...@microsoft.comwrote:
Is this helpful?
Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
I think, you forgot to add a RequiredFieldValidator for the EmpCaution
list

May 27 '07 #4
On May 27, 4:23 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 25, 11:08 pm, "dancer" <dan...@microsoft.comwrote:
Is this helpful?
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]

I think, you forgot to add a RequiredFieldValidator for the EmpCaution
list
Okay, the problem is in the very first line of your page

<%@ Page Language="VB" ClientTarget="downlevel" %>

Get rid of the ClientTarget and validation will work.

May 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: | last post by:
I am accessing the same error-containing ASP page on an ISP server using w2k IE6 but with different effect. On the first computer I get several line of HTML outputed by ASP, shown correctly by...
9
by: Mairhtin O'Feannag | last post by:
Hello, We have two machines we wish to use DPF. They are both RH ES 2.1, with DB2 8.2. I read the documentation CAREFULLY, and added the following line to my db2nodes.cfg file : 1 egret 0
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
10
by: Shawn | last post by:
JIT Debugging failed with the following error: Access is denied. JIT Debugging was initiated by the following account 'PLISKEN\ASPNET' I get this messag in a dialog window when I try to open an...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.