I have a sudoku grid with 81 cells(asp:textboxes) which I've labeled: _c11.._c12.._c13.._c99 I'm trying to format the textboxes on page load. The current code I have is returning 81 controls, but when I do formatting in the last loop its give me a null reference error.. Excuse my horrible coding.. please :)
ArrayList sudokuCells = new ArrayList();
for(int i = 11; i < 100; i++)
{
if (i == 20 || i == 30 || i == 40 || i == 50 || i == 60 || i == 70 || i == 80 || i == 90)
continue;
else
{
TextBox cell = (TextBox)Page.FindControl("_c" + i.ToString());
sudokuCells.Add(cell);
}
}
_c11.Text = sudokuCells.Count.ToString();
foreach (TextBox cell in sudokuCells)
{
cell.ForeColor = System.Drawing.Color.Red;
cell.MaxLength = 1;
}
this is in page_load, I'm not exactly why it's giving me a null reference, because I'm referencing all textbox controls in cell then adding that reference to the arraylist.
Obviously, I'm missing something will someone please educate me?
Ok.. Page.FindControl("_c11") returns a null; even though I have them defined in my aspx page.
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Content.aspx.cs" Inherits="Sudoku.Content" %>
<asp:Content ID="_content1" ContentPlaceHolderID="head" runat="server">
<link rel="stylesheet" type="text/css" href="styles/style.css" />
</asp:Content>
<asp:Content ID="_content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="wrapper">
<table cellpadding="0" cellspacing="0" class="sudokuTable">
<tr>
<td class="column1NoBottomBorder"><asp:TextBox ID="_c11" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
<td class="column2NoBottomBorder"><asp:TextBox ID="_c12" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
<td class="column3NoBottomBorder"><asp:TextBox ID="_c13" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
<td class="column4NoBottomBorder"><asp:TextBox ID="_c14" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
<td class="column5NoBottomBorder"><asp:TextBox ID="_c15" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
<td class="column6NoBottomBorder"><asp:TextBox ID="_c16" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
<td class="column7NoBottomBorder"><asp:TextBox ID="_c17" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
<td class="column8NoBottomBorder"><asp:TextBox ID="_c18" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
<td class="column9NoBottomBorder"><asp:TextBox ID="_c19" runat="server" CssClass="sudokuCell"></asp:TextBox></td>
</tr>
<tr>