Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Controls = NOTHING on Page_Load, cannot set control properties

Posted on 2004-10-26
13
Medium Priority
?
296 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
Comment
Question by:kerickson0328
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 10

Expert Comment

by:jnhorst
ID: 12413552
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
ID: 12414212
Hi kerickson0328,

can you post your code ?

Regards!
B..M
0
 

Author Comment

by:kerickson0328
ID: 12414392
Yes they are.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:kerickson0328
ID: 12414531
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
ID: 12414541
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
ID: 12414565
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
ID: 12415079
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:
Rejojohny earned 1000 total points
ID: 12415089
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
ID: 12415854
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
ID: 12415917
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
ID: 12415958
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
ID: 12415981
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
ID: 12415985
kerickson0328,

I see. Good luck

Regards!
B..M
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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