G
Guest
I'm writing what should be a very simple app against an Oracle database. The
app has a number of user controls, any one of which is loaded into a main
display page using the loadControl method, depending on which menu item a
user selects. Each of these controls follows the same basic pattern: Get a
dataset from the database and then display the results using basic
databinding.
Everything works fine except that I'll occaisionally get an IndexOutOfBounds
exception on an actual databinding command in the .ascx page. Here's an
example of the exception message:
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the
bounds of the array.
Source Error:
Line 21: </td>
Line 22: <td class="value">
Line 23: <%# CurrentRow["APPRV_COLLAT_VIN"] %>
Line 24: </td>
Line 25: <td class="label">
Source File: C:\inetpub\wwwroot\cart\Controls\CollateralAndFinanceData.ascx
Line: 23
Stack Trace:
[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Web.UI.DataBoundLiteralControl.SetDataBoundString(Int32 index,
String s) +14
ASP.CollateralAndFinanceData_ascx.__DataBind__control2(Object sender,
EventArgs e) in
C:\inetpub\wwwroot\cart\Controls\CollateralAndFinanceData.ascx:23
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
CART.Controls.CollateralAndFinanceData.GetData() +130
CART.Controls.CollateralAndFinanceData.Page_Load(Object sender, EventArgs
e) +5
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.AddedControl(Control control, Int32 index) +307
System.Web.UI.ControlCollection.Add(Control child) +153
CART.ViewApplication.set_CurrentControlName(String value) +112
CART.NavigationLink.linkButton_Click(Object sender, EventArgs e) +34
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +108
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1292
Notice that this is NOT the exception that's thrown if the field doesn't
exist in the row, nor the exception that would be raised if I was attempting
to access a row that doesn't exist. I've actually tried various ways of
getting to the field in the .cs code and writing the value to the trace. The
field is DEFINITELY there. The exception is actually on the
DataBoundLiteralControl.SetDataBoundString method.
What testing I've done seems to indicate that there's some sort of upper
limit to a page's (or other objects???) number of databound elements. I can
wrap various sections within panels, and this has often solved the problem.
That reinforces my theory that I'm running into a control's limitations --
each panel now has a fewer number of databound controls and the page now has
none itself.
Today I ran into the problem on yet another page, so I broke the page into
panels. What's interesting is that NOW I'm suddenly getting the error on yet
ANOTHER page (one that worked fine before), and it's on the 3rd databound
field. Now I'm thinking I'm running into some sort of limit on the total
number of databound fields available for the session, or some other sort of
limitation weirdness.
On another note (and possibly should be another thread) -- when I do break
one of these .ascx controls into panels, I've found the <asp
anel ... tag
can't be the first thing on the control, or I get a viewstate error.
Just as a sideline, I'm no newbie. I'm a senior developer and write this
kind of code day in and day out. This is the first app on which I've
encountered this kind of bizarre behaviour.
Some snippets from a standard control in my site:
From the .cs code behind:
...
public class ApplicantData : System.Web.UI.UserControl
{
private DataSet _data;
private void Page_Load(object sender, System.EventArgs e)
{
GetData();
}
private void GetData()
{
DataBase db = new DataBase();
_data = db.GetData("GetApplicantData");
this.DataBind();
}
public DataRow CurrentRow
{
get
{
DataRow returnRow = null;
if (_data == null)
{
GetData();
}
if (_data.Tables.Count > 0 && _data.Tables[0].Rows.Count > 0)
{
returnRow = _data.Tables[0].Rows[0];
}
return returnRow;
}
}
...
From the .ascx page:
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="ApplicantData.ascx.cs" Inherits="CART.Controls.ApplicantData"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<h2>Personal</h2>
<table class="dataTable" cellspacing="0">
<tr>
<td class="label">
First Name
</td>
<td class="value">
<%# CurrentRow["APLNT_FIRST_NM"] %>
</td>
<td class="label">
SSN
</td>
<td class="value">
<%# CurrentRow["APLNT_SSN"] %>
</td>
</tr>
<td class="label">
Middle Initial
</td>
<td class="value">
<%# CurrentRow["APLNT_MIDL_NM"] %>
</td>
<td class="label">
DOB
</td>
<td class="value">
<%# String.Format("{0:d}", CurrentRow["APLNT_BIRTH_DT"]) %>
</td>
<tr>
<td class="label">
Last Name
</td>
<td class="value">
<%# CurrentRow["APLNT_LAST_NM"] %>
</td>
<td class="label">
Age
</td>
<td class="value">
<%# CurrentRow["APLNT_AGE"] %>
</td>
</tr>
<tr>
<td class="label">
Suffix
</td>
<td class="value">
<%# CurrentRow["APLNT_SUFFX_NM"] %>
</td>
<td class="label">
Marital Status
</td>
<td class="value">
<%# CurrentRow["APLNT_MARITAL_STATUS_CD"] %>
</td>
</tr>
</table>
app has a number of user controls, any one of which is loaded into a main
display page using the loadControl method, depending on which menu item a
user selects. Each of these controls follows the same basic pattern: Get a
dataset from the database and then display the results using basic
databinding.
Everything works fine except that I'll occaisionally get an IndexOutOfBounds
exception on an actual databinding command in the .ascx page. Here's an
example of the exception message:
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the
bounds of the array.
Source Error:
Line 21: </td>
Line 22: <td class="value">
Line 23: <%# CurrentRow["APPRV_COLLAT_VIN"] %>
Line 24: </td>
Line 25: <td class="label">
Source File: C:\inetpub\wwwroot\cart\Controls\CollateralAndFinanceData.ascx
Line: 23
Stack Trace:
[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Web.UI.DataBoundLiteralControl.SetDataBoundString(Int32 index,
String s) +14
ASP.CollateralAndFinanceData_ascx.__DataBind__control2(Object sender,
EventArgs e) in
C:\inetpub\wwwroot\cart\Controls\CollateralAndFinanceData.ascx:23
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
CART.Controls.CollateralAndFinanceData.GetData() +130
CART.Controls.CollateralAndFinanceData.Page_Load(Object sender, EventArgs
e) +5
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.AddedControl(Control control, Int32 index) +307
System.Web.UI.ControlCollection.Add(Control child) +153
CART.ViewApplication.set_CurrentControlName(String value) +112
CART.NavigationLink.linkButton_Click(Object sender, EventArgs e) +34
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +108
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1292
Notice that this is NOT the exception that's thrown if the field doesn't
exist in the row, nor the exception that would be raised if I was attempting
to access a row that doesn't exist. I've actually tried various ways of
getting to the field in the .cs code and writing the value to the trace. The
field is DEFINITELY there. The exception is actually on the
DataBoundLiteralControl.SetDataBoundString method.
What testing I've done seems to indicate that there's some sort of upper
limit to a page's (or other objects???) number of databound elements. I can
wrap various sections within panels, and this has often solved the problem.
That reinforces my theory that I'm running into a control's limitations --
each panel now has a fewer number of databound controls and the page now has
none itself.
Today I ran into the problem on yet another page, so I broke the page into
panels. What's interesting is that NOW I'm suddenly getting the error on yet
ANOTHER page (one that worked fine before), and it's on the 3rd databound
field. Now I'm thinking I'm running into some sort of limit on the total
number of databound fields available for the session, or some other sort of
limitation weirdness.
On another note (and possibly should be another thread) -- when I do break
one of these .ascx controls into panels, I've found the <asp
can't be the first thing on the control, or I get a viewstate error.
Just as a sideline, I'm no newbie. I'm a senior developer and write this
kind of code day in and day out. This is the first app on which I've
encountered this kind of bizarre behaviour.
Some snippets from a standard control in my site:
From the .cs code behind:
...
public class ApplicantData : System.Web.UI.UserControl
{
private DataSet _data;
private void Page_Load(object sender, System.EventArgs e)
{
GetData();
}
private void GetData()
{
DataBase db = new DataBase();
_data = db.GetData("GetApplicantData");
this.DataBind();
}
public DataRow CurrentRow
{
get
{
DataRow returnRow = null;
if (_data == null)
{
GetData();
}
if (_data.Tables.Count > 0 && _data.Tables[0].Rows.Count > 0)
{
returnRow = _data.Tables[0].Rows[0];
}
return returnRow;
}
}
...
From the .ascx page:
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="ApplicantData.ascx.cs" Inherits="CART.Controls.ApplicantData"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<h2>Personal</h2>
<table class="dataTable" cellspacing="0">
<tr>
<td class="label">
First Name
</td>
<td class="value">
<%# CurrentRow["APLNT_FIRST_NM"] %>
</td>
<td class="label">
SSN
</td>
<td class="value">
<%# CurrentRow["APLNT_SSN"] %>
</td>
</tr>
<td class="label">
Middle Initial
</td>
<td class="value">
<%# CurrentRow["APLNT_MIDL_NM"] %>
</td>
<td class="label">
DOB
</td>
<td class="value">
<%# String.Format("{0:d}", CurrentRow["APLNT_BIRTH_DT"]) %>
</td>
<tr>
<td class="label">
Last Name
</td>
<td class="value">
<%# CurrentRow["APLNT_LAST_NM"] %>
</td>
<td class="label">
Age
</td>
<td class="value">
<%# CurrentRow["APLNT_AGE"] %>
</td>
</tr>
<tr>
<td class="label">
Suffix
</td>
<td class="value">
<%# CurrentRow["APLNT_SUFFX_NM"] %>
</td>
<td class="label">
Marital Status
</td>
<td class="value">
<%# CurrentRow["APLNT_MARITAL_STATUS_CD"] %>
</td>
</tr>
</table>