kerickson0328
asked on
Controls = NOTHING on Page_Load, cannot set control properties
I have a web form in a project that has suddenly become a problem.
I removed a checkbox that was working on the form, and added two radio buttons instead.
In the form's Page_Load routine, I read a DataRow item's value - and check the appropriate radio button.
The problem is - I get "...NullReferenceException - Object not set to an instance of an object." on the line setting the Checked property.
If I break on that line, my radio button is indeed Nothing. I next put a new label on the page, and set it's text in the form's Page_Load routine - SAME PROBLEM - NullReferenceException - Object not set to an instance of an object."
In both cases, the region "Web Form Designer Generated Code" DOES contain the lines Protected WithEvents... declaring the new controls.
Any ideas what could this problem be caused by???? How can I resolve it???? Thanks in advance!
I removed a checkbox that was working on the form, and added two radio buttons instead.
In the form's Page_Load routine, I read a DataRow item's value - and check the appropriate radio button.
The problem is - I get "...NullReferenceException
If I break on that line, my radio button is indeed Nothing. I next put a new label on the page, and set it's text in the form's Page_Load routine - SAME PROBLEM - NullReferenceException - Object not set to an instance of an object."
In both cases, the region "Web Form Designer Generated Code" DOES contain the lines Protected WithEvents... declaring the new controls.
Any ideas what could this problem be caused by???? How can I resolve it???? Thanks in advance!
Hi kerickson0328,
can you post your code ?
Regards!
B..M
can you post your code ?
Regards!
B..M
ASKER
Yes they are.
ASKER
Here's the HTML ------->
<%@ Page EnableSessionState="True" Language="vb" AutoEventWireup="false" Codebehind="employereditna me.aspx.vb " Inherits="_4NCAlert.employ ereditname " errorPage="errpage.aspx" %>
<%@ Register TagPrefix="uc1" TagName="header" Src="../header.ascx" %>
<%@ Register TagPrefix="uc1" TagName="clientmenu" Src="../clientmenu.ascx" %>
<%@ Register TagPrefix="uc1" TagName="footer" Src="../footer.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>employereditname</t itle>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScri pt" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK media="screen" href="../bus037.css" rel="stylesheet">
</HEAD>
<body background="../images/bg.g if">
<form id="Form1" method="post" runat="server">
<CENTER>
<table cellSpacing="1" cellPadding="0" width="770" bgColor="black" border="0">
<tr>
<td width="201" bgColor="#f1f9ff" valign="top">
<table cellSpacing="0" cellPadding="0" width="201" border="0">
<tr>
<td width="201"><IMG alt="" src="../images/logo.jpg">< /td>
</tr>
<tr>
<td width="201">
<p><B>Employer Naviga tion Menu</B></p>
<UL>
<LI>
<A href="EmployerManageNames. aspx">Mana ge Na mes</A>
<LI>
<A href="EmployerMatches.aspx ">View&nbs p;Match Activity</A>
<LI>
<A href="EmployerEditProfile. aspx">Edit Employer Profile</A>
<LI>
<A href="EmployerMain.aspx">E mployer Home</A></LI></UL>
<P><b>Contact Information</b></P>
</td>
</tr>
</table>
<p><br>
</p>
</td>
<td vAlign="top" width="569" bgColor="#f1f9ff">
<h1>4NCAlert Employer -
<asp:Label id="lblEmployer" runat="server"></asp:Label ></h1>
<h2>
Edit Employee Information</h2>
<P>Edit the employee's information below, then click submit to save your changes.</P>
<P>
<TABLE id="Table2" style="WIDTH: 455px; HEIGHT: 392px" cellSpacing="1" cellPadding="1"
width="455" bgColor="#f1f9ff" border="0">
<TR>
<TD style="WIDTH: 125px; HEIGHT: 24px"><FONT face="Arial" color="#000099" size="1">Client ID:</ FONT></TD>
<TD style="HEIGHT: 24px"><FONT face="Arial" color="#000099">
<asp:Label id="lblClientID" runat="server"></asp:Label ><FONT size="1"></FONT></FONT></T D>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 1px"><FONT face="Arial" color="#000099" size="1">Employer
ID:</FONT></TD>
<TD style="HEIGHT: 1px">
<asp:Label id="lblEmployerID" runat="server" Font-Names="Arial" ForeColor="Navy" Font-Size="XX-Small"></asp :Label><FO NT face="Arial" color="#000099" size="1"></FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 18px"><FONT face="Arial" color="#000099" size="1">Employee
ID:</FONT></TD>
<TD style="HEIGHT: 18px">
<asp:TextBox id="txtEmployeeID" runat="server" Width="154px"></asp:TextBo x>
<asp:requiredfieldvalidato r id="RequiredFieldValidator 2" runat="server" Font-Names="Arial" Font-Size="XX-Small"
ErrorMessage="EmployeeID is Required." ControlToValidate="txtEmpl oyeeID"></ asp:requir edfieldval idator><FO NT face="Arial" color="#000099" size="1"></FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 24px"><FONT face="Arial" color="#000099" size="1">First
Name:</FONT></TD>
<TD style="HEIGHT: 24px">
<asp:TextBox id="txtFirstName" runat="server" Width="154px"></asp:TextBo x>
<asp:requiredfieldvalidato r id="RequiredFieldValidator 3" runat="server" Font-Names="Arial" Font-Size="XX-Small"
ErrorMessage="First Name is Required." ControlToValidate="txtFirs tName"></a sp:require dfieldvali dator><FON T face="Arial" color="#000099" size="1"></FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 16px"><FONT face="Arial" color="#000099" size="1">Mid.
Name/IN:</FONT></TD>
<TD style="HEIGHT: 16px">
<asp:TextBox id="txtMidName" runat="server"></asp:TextB ox><FONT face="Arial" color="#000099" size="1"></FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 14px"><FONT face="Arial" color="#000099" size="1">Last
Name:</FONT></TD>
<TD style="HEIGHT: 14px">
<asp:TextBox id="txtLastName" runat="server" Width="153px"></asp:TextBo x>
<asp:requiredfieldvalidato r id="Requiredfieldvalidator 6" runat="server" Font-Names="Arial" Font-Size="XX-Small"
ErrorMessage="Last Name is Required." ControlToValidate="txtLast Name"></as p:required fieldvalid ator><FONT face="Arial" color="#000099" size="1"></FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 14px"><FONT face="Arial" color="#000099" size="1">Suffix:</FONT></T D>
<TD style="HEIGHT: 14px">
<asp:TextBox id="txtSuffix" runat="server" Width="153px"></asp:TextBo x><FONT face="Arial" color="#000099" size="1"></FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 20px"><FONT face="Arial" color="#000099" size="1">Date
Of Birth:</FONT></TD>
<TD style="HEIGHT: 20px">
<asp:TextBox id="txtDOB" runat="server"></asp:TextB ox>
<asp:requiredfieldvalidato r id="RequiredFieldValidator 5" runat="server" Font-Names="Arial" Font-Size="XX-Small"
ErrorMessage="Date Of Birth is Required." ControlToValidate="txtDOB" Height="8px"></asp:require dfieldvali dator>
<asp:regularexpressionvali dator id="RegularExpressionValid ator1" runat="server" Font-Names="Arial" Font-Size="XX-Small"
ErrorMessage="Use Format MM/DD/YYYY" ControlToValidate="txtDOB" ValidationExpression="^(|( 0[1-9])|(1 [0-2]))\/( (0[1-9])|( 1\d)|(2\d) |(3[0-1])) \/((\d{4}) )$"></asp: regularexp ressionval idator><FO NT face="Arial" color="#000099" size="2"><STRONG></STRONG> </FONT></T D>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 25px"><FONT face="Arial" color="#000099" size="2"><STRONG></STRONG> </FONT></T D>
<TD style="HEIGHT: 25px"><FONT face="Arial" color="#000099" size="2">
<asp:Label id="lblActive" runat="server"></asp:Label > &nb sp;<BR>
<asp:CheckBox id="chkActive" runat="server"></asp:Check Box></FONT ></TD>
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 20px"><FONT face="Arial" color="#000099" size="2"><STRONG>
<P align="center">
<asp:Button id="btnSubmit" runat="server" ForeColor="White" BorderStyle="Ridge" BackColor="Gray"
Text="Submit"></asp:Button ></P>
</STRONG></FONT>
</TD>
<TD style="HEIGHT: 20px"><FONT face="Arial" color="#000099" size="2"><STRONG>
<asp:Label id="lblStatus" runat="server" Font-Names="Arial" Font-Bold="True" ForeColor="Red"></asp:Labe l></STRONG ></FONT></ TD>
</TR>
<TR>
<TD style="WIDTH: 105px" vAlign="top" colSpan="2">
<P align="center"> </P>
</TD>
</TR>
</TABLE>
</P>
<P> </P>
</td>
</tr>
<tr>
<td width="720" bgColor="#f1f9ff" colSpan="2"><IMG alt="" src="../images/footer.gif" ></td>
</tr>
<tr height="14">
<td width="720" bgColor="#f1f9ff" colSpan="2" height="14">
</td>
</tr>
</table>
</CENTER>
</form>
</body>
</HTML>
<%@ Page EnableSessionState="True" Language="vb" AutoEventWireup="false" Codebehind="employereditna
<%@ Register TagPrefix="uc1" TagName="header" Src="../header.ascx" %>
<%@ Register TagPrefix="uc1" TagName="clientmenu" Src="../clientmenu.ascx" %>
<%@ Register TagPrefix="uc1" TagName="footer" Src="../footer.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>employereditname</t
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScri
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK media="screen" href="../bus037.css" rel="stylesheet">
</HEAD>
<body background="../images/bg.g
<form id="Form1" method="post" runat="server">
<CENTER>
<table cellSpacing="1" cellPadding="0" width="770" bgColor="black" border="0">
<tr>
<td width="201" bgColor="#f1f9ff" valign="top">
<table cellSpacing="0" cellPadding="0" width="201" border="0">
<tr>
<td width="201"><IMG alt="" src="../images/logo.jpg"><
</tr>
<tr>
<td width="201">
<p><B>Employer Naviga
<UL>
<LI>
<A href="EmployerManageNames.
<LI>
<A href="EmployerMatches.aspx
<LI>
<A href="EmployerEditProfile.
<LI>
<A href="EmployerMain.aspx">E
<P><b>Contact Information</b></P>
</td>
</tr>
</table>
<p><br>
</p>
</td>
<td vAlign="top" width="569" bgColor="#f1f9ff">
<h1>4NCAlert Employer -
<asp:Label id="lblEmployer" runat="server"></asp:Label
<h2>
Edit Employee Information</h2>
<P>Edit the employee's information below, then click submit to save your changes.</P>
<P>
<TABLE id="Table2" style="WIDTH: 455px; HEIGHT: 392px" cellSpacing="1" cellPadding="1"
width="455" bgColor="#f1f9ff" border="0">
<TR>
<TD style="WIDTH: 125px; HEIGHT: 24px"><FONT face="Arial" color="#000099" size="1">Client ID:</
<TD style="HEIGHT: 24px"><FONT face="Arial" color="#000099">
<asp:Label id="lblClientID" runat="server"></asp:Label
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 1px"><FONT face="Arial" color="#000099" size="1">Employer
ID:</FONT></TD>
<TD style="HEIGHT: 1px">
<asp:Label id="lblEmployerID" runat="server" Font-Names="Arial" ForeColor="Navy" Font-Size="XX-Small"></asp
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 18px"><FONT face="Arial" color="#000099" size="1">Employee
ID:</FONT></TD>
<TD style="HEIGHT: 18px">
<asp:TextBox id="txtEmployeeID" runat="server" Width="154px"></asp:TextBo
<asp:requiredfieldvalidato
ErrorMessage="EmployeeID is Required." ControlToValidate="txtEmpl
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 24px"><FONT face="Arial" color="#000099" size="1">First
Name:</FONT></TD>
<TD style="HEIGHT: 24px">
<asp:TextBox id="txtFirstName" runat="server" Width="154px"></asp:TextBo
<asp:requiredfieldvalidato
ErrorMessage="First Name is Required." ControlToValidate="txtFirs
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 16px"><FONT face="Arial" color="#000099" size="1">Mid.
Name/IN:</FONT></TD>
<TD style="HEIGHT: 16px">
<asp:TextBox id="txtMidName" runat="server"></asp:TextB
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 14px"><FONT face="Arial" color="#000099" size="1">Last
Name:</FONT></TD>
<TD style="HEIGHT: 14px">
<asp:TextBox id="txtLastName" runat="server" Width="153px"></asp:TextBo
<asp:requiredfieldvalidato
ErrorMessage="Last Name is Required." ControlToValidate="txtLast
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 14px"><FONT face="Arial" color="#000099" size="1">Suffix:</FONT></T
<TD style="HEIGHT: 14px">
<asp:TextBox id="txtSuffix" runat="server" Width="153px"></asp:TextBo
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 20px"><FONT face="Arial" color="#000099" size="1">Date
Of Birth:</FONT></TD>
<TD style="HEIGHT: 20px">
<asp:TextBox id="txtDOB" runat="server"></asp:TextB
<asp:requiredfieldvalidato
ErrorMessage="Date Of Birth is Required." ControlToValidate="txtDOB"
<asp:regularexpressionvali
ErrorMessage="Use Format MM/DD/YYYY" ControlToValidate="txtDOB"
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 25px"><FONT face="Arial" color="#000099" size="2"><STRONG></STRONG>
<TD style="HEIGHT: 25px"><FONT face="Arial" color="#000099" size="2">
<asp:Label id="lblActive" runat="server"></asp:Label
<asp:CheckBox id="chkActive" runat="server"></asp:Check
</TR>
<TR>
<TD style="WIDTH: 125px; HEIGHT: 20px"><FONT face="Arial" color="#000099" size="2"><STRONG>
<P align="center">
<asp:Button id="btnSubmit" runat="server" ForeColor="White" BorderStyle="Ridge" BackColor="Gray"
Text="Submit"></asp:Button
</STRONG></FONT>
</TD>
<TD style="HEIGHT: 20px"><FONT face="Arial" color="#000099" size="2"><STRONG>
<asp:Label id="lblStatus" runat="server" Font-Names="Arial" Font-Bold="True" ForeColor="Red"></asp:Labe
</TR>
<TR>
<TD style="WIDTH: 105px" vAlign="top" colSpan="2">
<P align="center"> </P>
</TD>
</TR>
</TABLE>
</P>
<P> </P>
</td>
</tr>
<tr>
<td width="720" bgColor="#f1f9ff" colSpan="2"><IMG alt="" src="../images/footer.gif"
</tr>
<tr height="14">
<td width="720" bgColor="#f1f9ff" colSpan="2" height="14">
</td>
</tr>
</table>
</CENTER>
</form>
</body>
</HTML>
ASKER
Here's the code for Page_Load ----->
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Fill text boxes w/name info
oName = New AlertName
Dim row As DataRow = oName.GetAlertName(Session ("CurrentC ontrolID") )
lblClientID.Text = Session("ClientID")
lblEmployerID.Text = row("employerID")
lblEmployer.Text = oEmployer.GetEmployerName( Session("C urrentEmpl oyerID"))
txtEmployeeID.Text = row("employeeID")
txtFirstName.Text = row("fname")
If Not IsDBNull(row("minitial")) Then
txtMidName.Text = row("minitial")
Else
txtMidName.Text = ""
End If
txtLastName.Text = row("lname")
If Not IsDBNull(row("suffix")) Then
txtSuffix.Text = row("suffix")
Else
txtSuffix.Text = ""
End If
If Not IsDBNull(row("dob")) Then
txtDOB.Text = row("dob")
Else
txtDOB.Text = ""
End If
If row("active") = 1 Then
lblActive.Text = "Employee Current Status - Active"
iAct = 1
ElseIf row("active") = 0 Then
lblActive.Text = "Employee Current Status - Inactive"
iAct = 0
End If
Else
End If
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Fill text boxes w/name info
oName = New AlertName
Dim row As DataRow = oName.GetAlertName(Session
lblClientID.Text = Session("ClientID")
lblEmployerID.Text = row("employerID")
lblEmployer.Text = oEmployer.GetEmployerName(
txtEmployeeID.Text = row("employeeID")
txtFirstName.Text = row("fname")
If Not IsDBNull(row("minitial")) Then
txtMidName.Text = row("minitial")
Else
txtMidName.Text = ""
End If
txtLastName.Text = row("lname")
If Not IsDBNull(row("suffix")) Then
txtSuffix.Text = row("suffix")
Else
txtSuffix.Text = ""
End If
If Not IsDBNull(row("dob")) Then
txtDOB.Text = row("dob")
Else
txtDOB.Text = ""
End If
If row("active") = 1 Then
lblActive.Text = "Employee Current Status - Active"
iAct = 1
ElseIf row("active") = 0 Then
lblActive.Text = "Employee Current Status - Inactive"
iAct = 0
End If
Else
End If
End Sub
ASKER
lblActive is the control currently causing this error. The others (created prior to today) do not cause error.
Thanks for looking at this.
Thanks for looking at this.
kerickson0328,
try to comment the lines that lblActive is used and try to rebuild
after that uncomment the lines and try to rebuild the solution
Regards!
B..M
try to comment the lines that lblActive is used and try to rebuild
after that uncomment the lines and try to rebuild the solution
Regards!
B..M
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, this I've never seen... mmarinov - I commented out the 2 lines in code that set lblActive Text property. When I run the project, the web form loads (no more error), BUT the form still has the OLD checkbox that I deleted earlier today. In VS.NET however, the designer shows the form as it SHOULD be - old checkbox gone, but with new label - lblActive & new checkbox.
Rejojohny - I added the control through the designer, but when I double-click the new checkbox, nothing happens. When I double-click the new label it goes to my now commented line in the code lblActive.text = ....
thanks to you both!
Rejojohny - I added the control through the designer, but when I double-click the new checkbox, nothing happens. When I double-click the new label it goes to my now commented line in the code lblActive.text = ....
thanks to you both!
kerickson0328,
it sounds like a VS.NET gone crazy
if it is not a problem - restart the pc - and all have to be ok
Regards!
B..M
it sounds like a VS.NET gone crazy
if it is not a problem - restart the pc - and all have to be ok
Regards!
B..M
ASKER
Wow - the things you miss sometimes!! I found the reason I've been having this problem, thanks to your suggestions.
I had recently moved this form to a new diretory in the site, and simply removed the previous copy from the site root directory.
I found that I was being redirected to the OLD copy in the root, b/c I missed adding the folder to the path in an html link. Once I deleted the old file and made sure I had updated all the links in the site to point to the forms in the new directory - of course - it works just fine!
I had recently moved this form to a new diretory in the site, and simply removed the previous copy from the site root directory.
I found that I was being redirected to the OLD copy in the root, b/c I missed adding the folder to the path in an html link. Once I deleted the old file and made sure I had updated all the links in the site to point to the forms in the new directory - of course - it works just fine!
ASKER
correction above - I removed the old copy from the project in .NET, it still existed, so my bad links were still 'working'.
kerickson0328,
I see. Good luck
Regards!
B..M
I see. Good luck
Regards!
B..M
John