Solved

Controls = NOTHING on Page_Load, cannot set control properties

Posted on 2004-10-26
290 Views
Last Modified: 2008-03-10
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!
0
Question by:kerickson0328
    13 Comments
     
    LVL 10

    Expert Comment

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

    John
    0
     
    LVL 28

    Expert Comment

    by:mmarinov
    Hi kerickson0328,

    can you post your code ?

    Regards!
    B..M
    0
     

    Author Comment

    by:kerickson0328
    Yes they are.
    0
     

    Author Comment

    by:kerickson0328
    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>
    0
     

    Author Comment

    by:kerickson0328
    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
    0
     

    Author Comment

    by:kerickson0328
    lblActive is the control currently causing this error.  The others (created prior to today) do not cause error.

    Thanks for looking at this.
    0
     
    LVL 28

    Expert Comment

    by:mmarinov
    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
    0
     
    LVL 26

    Accepted Solution

    by:
    how did u add the control .. did u use the designer or just addded the line in the HTML code .. what happens when u doubleclick on the control in the design mode .. does it take u to th code-behind? i have faced similar problems when i add a control in the HTML code directly and do not go to the designer ...
    0
     

    Author Comment

    by:kerickson0328
    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!
    0
     
    LVL 28

    Expert Comment

    by:mmarinov
    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
    0
     

    Author Comment

    by:kerickson0328
    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!
    0
     

    Author Comment

    by:kerickson0328
    correction above - I removed the old copy from the project in .NET, it still existed, so my bad links were still 'working'.
    0
     
    LVL 28

    Expert Comment

    by:mmarinov
    kerickson0328,

    I see. Good luck

    Regards!
    B..M
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now