Link to home
Start Free TrialLog in
Avatar of kerickson0328
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!
Avatar of jnhorst
jnhorst

Are these controls within the <form runat="server"...></form> tag in the HTML view of the aspx page?

John
Hi kerickson0328,

can you post your code ?

Regards!
B..M
Avatar of kerickson0328

ASKER

Yes they are.
Here's the HTML ------->

<%@ Page EnableSessionState="True" Language="vb" AutoEventWireup="false" Codebehind="employereditname.aspx.vb" Inherits="_4NCAlert.employereditname" 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</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
            <meta name="vs_defaultClientScript" 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.gif">
            <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&nbsp;Navigation Menu</B></p>
                                                            <UL>
                                                                  <LI>
                                                                        <A href="EmployerManageNames.aspx">Manage&nbsp;Names</A>
                                                                  <LI>
                                                                        <A href="EmployerMatches.aspx">View&nbsp;Match Activity</A>
                                                                  <LI>
                                                                        <A href="EmployerEditProfile.aspx">Edit Employer Profile</A>
                                                                  <LI>
                                                                        <A href="EmployerMain.aspx">Employer 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&nbsp;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></TD>
                                                      </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><FONT 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:TextBox>
                                                                  <asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" Font-Names="Arial" Font-Size="XX-Small"
                                                                        ErrorMessage="EmployeeID is Required." ControlToValidate="txtEmployeeID"></asp:requiredfieldvalidator><FONT 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:TextBox>
                                                                  <asp:requiredfieldvalidator id="RequiredFieldValidator3" runat="server" Font-Names="Arial" Font-Size="XX-Small"
                                                                        ErrorMessage="First Name is Required." ControlToValidate="txtFirstName"></asp:requiredfieldvalidator><FONT 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:TextBox><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:TextBox>
                                                                  <asp:requiredfieldvalidator id="Requiredfieldvalidator6" runat="server" Font-Names="Arial" Font-Size="XX-Small"
                                                                        ErrorMessage="Last Name is Required." ControlToValidate="txtLastName"></asp:requiredfieldvalidator><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></TD>
                                                            <TD style="HEIGHT: 14px">
                                                                  <asp:TextBox id="txtSuffix" runat="server" Width="153px"></asp:TextBox><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:TextBox>
                                                                  <asp:requiredfieldvalidator id="RequiredFieldValidator5" runat="server" Font-Names="Arial" Font-Size="XX-Small"
                                                                        ErrorMessage="Date Of Birth is Required." ControlToValidate="txtDOB" Height="8px"></asp:requiredfieldvalidator>
                                                                  <asp:regularexpressionvalidator id="RegularExpressionValidator1" 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:regularexpressionvalidator><FONT face="Arial" color="#000099" size="2"><STRONG></STRONG></FONT></TD>
                                                      </TR>
                                                      <TR>
                                                            <TD style="WIDTH: 125px; HEIGHT: 25px"><FONT face="Arial" color="#000099" size="2"><STRONG></STRONG></FONT></TD>
                                                            <TD style="HEIGHT: 25px"><FONT face="Arial" color="#000099" size="2">&nbsp;
                                                                        <asp:Label id="lblActive" runat="server"></asp:Label>&nbsp;&nbsp;<BR>
                                                                        &nbsp;
                                                                        <asp:CheckBox id="chkActive" runat="server"></asp:CheckBox></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:Label></STRONG></FONT></TD>
                                                      </TR>
                                                      <TR>
                                                            <TD style="WIDTH: 105px" vAlign="top" colSpan="2">
                                                                  <P align="center">&nbsp;</P>
                                                            </TD>
                                                      </TR>
                                                </TABLE>
                                          </P>
                                          <P>&nbsp;</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>
                  &nbsp;
            </form>
      </body>
</HTML>
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("CurrentControlID"))
            lblClientID.Text = Session("ClientID")
            lblEmployerID.Text = row("employerID")
            lblEmployer.Text = oEmployer.GetEmployerName(Session("CurrentEmployerID"))
            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
lblActive is the control currently causing this error.  The others (created prior to today) do not cause error.

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
ASKER CERTIFIED SOLUTION
Avatar of Rejojohny
Rejojohny
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
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
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!
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