Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Control in User Control not instantiating

Reply
Thread Tools

Control in User Control not instantiating

 
 
John Teague
Guest
Posts: n/a
 
      03-18-2005
am building a user control that has a repeater in it. I first started with a
regular web page to get the formatting right where everything worked
properly. I then copied it into a new ascx file.

The repeater is created on the page (not dynamic). I have a function that
databinds the repeater:

private void BindRepeater(){
DataSet ds = new DataSet();
.. . . create dataset structure . . .;

repeater.datasource = ds; //error occurs here
repeater.Databind();
}

I get an error message that object reference not set to an instance. When I
step through with the debugger, the repeater is not instantiated.

This only happened after I moved it to an ascx page and put the control on
an aspx page. I have tried calling this function in the page_load, init, and
prerender.

Any suggestions?
 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      03-18-2005
Well, since we don't have your ASCX file I can only make a guess at the problem
-- Did you add runat=server to your Repeater? Does it have an id="repeater"
(the variable name you referenced below)?

-Brock
DevelopMentor
http://staff.develop.com/ballen



> am building a user control that has a repeater in it. I first started
> with a regular web page to get the formatting right where everything
> worked properly. I then copied it into a new ascx file.
>
> The repeater is created on the page (not dynamic). I have a function
> that databinds the repeater:
>
> private void BindRepeater(){ DataSet ds = new DataSet(); . . . create
> dataset structure . . .;
>
> repeater.datasource = ds; //error occurs here repeater.Databind(); }
>
> I get an error message that object reference not set to an instance.
> When I step through with the debugger, the repeater is not
> instantiated.
>
> This only happened after I moved it to an ascx page and put the
> control on an aspx page. I have tried calling this function in the
> page_load, init, and prerender.
>
> Any suggestions?
>




 
Reply With Quote
 
 
 
 
John Teague
Guest
Posts: n/a
 
      03-18-2005
The answer is yes to both of your questions. My code has been review by
other developers and nothing was glarringly wrong with the code (at least to
us .

Here is the repeater tag:
<asp:repeater id=rptCommissionTable runat="server"
OnItemDataBound="rptCommissionTable_ItemDataBound" >
<HeaderTemplate>
<table border="1" cellpadding="0" cellpadding="0">
<tr>
<td colspan="12">Universal Life</td>
</tr>
<tr>
<td rowspan="3">
Carrier
</td>
<td rowspan="3">Product Compensation Schedule</td>
<td colspan="10">Total Commissions as a Function of Penetration
Percentage</td>
</tr>
<tr>
<td colspan="5">Advisor A</td>
<td colspan="5">Advisor B</td>
</tr>
<tr>
<td>30%</td>
<td>40%</td>
<td>50%</td>
<td>60%</td>
<td>70%</td>
<td>30%</td>
<td>40%</td>
<td>50%</td>
<td>60%</td>
<td>70%</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:Label ID="lblCompensationSchedule" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorARate1" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorARate2" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorARate3" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorARate4" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorARate5" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorBRate1" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorBRate2" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorBRate3" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorBRate4" Runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblAdvisorBRate5" Runat="server"></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

and the current codebehind (I have changed this many times to find the
problem)

namespace NFP.Benefits.VoluntaryBenefits.Commissions
{
/// <summary>
/// Summary description for VBCommissionMatrix.
/// </summary>
public class VBCommissionMatrix : System.Web.UI.UserControl
{
protected MetaBuilders.WebControls.GlobalRadioButton rb = new
GlobalRadioButton();
protected System.Web.UI.WebControls.Repeater rptCommissionTable;
protected Label lblTest;
private int commisionTableRowCount = 1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here



}
protected override void OnPreRender(EventArgs e)
{

base.OnPreRender (e);
}

private void BindCommissionRepeater()
{
DataSet ds = new DataSet();
DataTable dt1 = new DataTable();
dt1.Columns.Add("Carrier");
dt1.Columns.Add("CompensationSchedule");
dt1.Columns.Add("AdvisorARate1");
dt1.Columns.Add("AdvisorARate2");
dt1.Columns.Add("AdvisorARate3");
dt1.Columns.Add("AdvisorARate4");
dt1.Columns.Add("AdvisorARate5");
dt1.Columns.Add("AdvisorBRate1");
dt1.Columns.Add("AdvisorBRate2");
dt1.Columns.Add("AdvisorBRate3");
dt1.Columns.Add("AdvisorBRate4");
dt1.Columns.Add("AdvisorBRate5");

DataRow row1 = dt1.NewRow();
row1[0] = "Boston Mutual";
row1[1] = "First Year 90%";
row1[2] = "10,530";
row1[3] = "14,040";
row1[4] = "17,550";
row1[5] = "21,060";
row1[6] = "24,570";
row1[7] = "7,020";
row1[8] = "9,360";
row1[9] = "11,700";
row1[10] = "14,040";
row1[11] = "16,380";
dt1.Rows.Add(row1);

DataRow row2 = dt1.NewRow();
row2[0] = "Boston Mutual";
row2[1] = "Renewal 7%";
row2[2] = "819";
row2[3] = "1,092";
row2[4] = "1,365";
row2[5] = "1,638";
row2[6] = "1,911";
row2[7] = "546";
row2[8] = "728";
row2[9] = "910";
row2[10] = "1,092";
row2[11] = "1,274";
dt1.Rows.Add(row2);

DataRow row3 = dt1.NewRow();
row3[0] = "Boston Mutual";
row3[1] = "First Year 90%";
row3[2] = "10,530";
row3[3] = "14,040";
row3[4] = "17,550";
row3[5] = "21,060";
row3[6] = "24,570";
row3[7] = "7,020";
row3[8] = "9,360";
row3[9] = "11,700";
row3[10] = "14,040";
row3[11] = "16,380";
dt1.Rows.Add(row3);

DataRow row4 = dt1.NewRow();
row4[0] = "Boston Mutual";
row4[1] = "Renewal 7%";
row4[2] = "819";
row4[3] = "1,092";
row4[4] = "1,365";
row4[5] = "1,638";
row4[6] = "1,911";
row4[7] = "546";
row4[8] = "728";
row4[9] = "910";
row4[10] = "1,092";
row4[11] = "1,274";
dt1.Rows.Add(row4);
ds.Tables.Add(dt1);


this.rptCommissionTable.DataSource = ds;
this.rptCommissionTable.DataBind();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//

InitializeComponent();
base.OnInit(e);

}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

protected void rptCommissionTable_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
DataRowView data = (DataRowView)e.Item.DataItem;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
if(this.commisionTableRowCount % 2 == 0)
{
//e.Item.Controls.RemoveAt(2);
}
else
{
HtmlTableCell carrierCell = new HtmlTableCell();

GlobalRadioButton grb = new GlobalRadioButton();
grb.Text = data["Carrier"].ToString();
grb.GroupName = this.ID + "_radiogroup";

carrierCell.RowSpan = 2;
carrierCell.Controls.Add(grb);
//carrierCell.InnerText = data["Carrier"].ToString();
((HtmlTableRow)e.Item.Controls[1]).Cells.Insert(0,carrierCell);

}
((Label)e.Item.FindControl("lblCompensationSchedul e")).Text =
data["CompensationSchedule"].ToString();
((Label)e.Item.FindControl("lblAdvisorARate1")).Te xt =
data["AdvisorARate1"].ToString();
((Label)e.Item.FindControl("lblAdvisorARate2")).Te xt =
data["AdvisorARate2"].ToString();
((Label)e.Item.FindControl("lblAdvisorARate3")).Te xt =
data["AdvisorARate3"].ToString();
((Label)e.Item.FindControl("lblAdvisorARate4")).Te xt =
data["AdvisorARate4"].ToString();
((Label)e.Item.FindControl("lblAdvisorARate5")).Te xt =
data["AdvisorARate5"].ToString();
((Label)e.Item.FindControl("lblAdvisorBRate1")).Te xt =
data["AdvisorBRate1"].ToString();
((Label)e.Item.FindControl("lblAdvisorBRate2")).Te xt =
data["AdvisorBRate2"].ToString();
((Label)e.Item.FindControl("lblAdvisorBRate3")).Te xt =
data["AdvisorBRate3"].ToString();
((Label)e.Item.FindControl("lblAdvisorBRate4")).Te xt =
data["AdvisorBRate4"].ToString();
((Label)e.Item.FindControl("lblAdvisorBRate5")).Te xt =
data["AdvisorBRate5"].ToString();
this.commisionTableRowCount++;
}
}

}
}


Thanks for the help
 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      03-19-2005
Well, I copied this code into a ASPX and did two things:

1) Called BindCommissionRepeater() from Page_Load
2) Commented out the references to GlobalRadioButton

And it worked fine. I'm not sure what the real problem is then

-Brock
DevelopMentor
http://staff.develop.com/ballen



> The answer is yes to both of your questions. My code has been review
> by other developers and nothing was glarringly wrong with the code (at
> least to us .
>
> Here is the repeater tag:
> <asp:repeater id=rptCommissionTable runat="server"
> OnItemDataBound="rptCommissionTable_ItemDataBound" >
> <HeaderTemplate>
> <table border="1" cellpadding="0" cellpadding="0">
> <tr>
> <td colspan="12">Universal Life</td>
> </tr>
> <tr>
> <td rowspan="3">
> Carrier
> </td>
> <td rowspan="3">Product Compensation Schedule</td>
> <td colspan="10">Total Commissions as a Function of
> Penetration
> Percentage</td>
> </tr>
> <tr>
> <td colspan="5">Advisor A</td>
> <td colspan="5">Advisor B</td>
> </tr>
> <tr>
> <td>30%</td>
> <td>40%</td>
> <td>50%</td>
> <td>60%</td>
> <td>70%</td>
> <td>30%</td>
> <td>40%</td>
> <td>50%</td>
> <td>60%</td>
> <td>70%</td>
> </tr>
> </HeaderTemplate>
> <ItemTemplate>
> <tr runat="server">
> <td>
> <asp:Label ID="lblCompensationSchedule"
> Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorARate1" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorARate2" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorARate3" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorARate4" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorARate5" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorBRate1" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorBRate2" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorBRate3" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorBRate4" Runat="server"></asp:Label>
> </td>
> <td>
> <asp:Label ID="lblAdvisorBRate5" Runat="server"></asp:Label>
> </td>
> </tr>
> </ItemTemplate>
> <FooterTemplate>
> </table>
> </FooterTemplate>
> </asp:Repeater>
> and the current codebehind (I have changed this many times to find the
> problem)
>
> namespace NFP.Benefits.VoluntaryBenefits.Commissions
> {
> /// <summary>
> /// Summary description for VBCommissionMatrix.
> /// </summary>
> public class VBCommissionMatrix : System.Web.UI.UserControl
> {
> protected MetaBuilders.WebControls.GlobalRadioButton rb = new
> GlobalRadioButton();
> protected System.Web.UI.WebControls.Repeater rptCommissionTable;
> protected Label lblTest;
> private int commisionTableRowCount = 1;
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> }
> protected override void OnPreRender(EventArgs e)
> {
> base.OnPreRender (e);
> }
> private void BindCommissionRepeater()
> {
> DataSet ds = new DataSet();
> DataTable dt1 = new DataTable();
> dt1.Columns.Add("Carrier");
> dt1.Columns.Add("CompensationSchedule");
> dt1.Columns.Add("AdvisorARate1");
> dt1.Columns.Add("AdvisorARate2");
> dt1.Columns.Add("AdvisorARate3");
> dt1.Columns.Add("AdvisorARate4");
> dt1.Columns.Add("AdvisorARate5");
> dt1.Columns.Add("AdvisorBRate1");
> dt1.Columns.Add("AdvisorBRate2");
> dt1.Columns.Add("AdvisorBRate3");
> dt1.Columns.Add("AdvisorBRate4");
> dt1.Columns.Add("AdvisorBRate5");
> DataRow row1 = dt1.NewRow();
> row1[0] = "Boston Mutual";
> row1[1] = "First Year 90%";
> row1[2] = "10,530";
> row1[3] = "14,040";
> row1[4] = "17,550";
> row1[5] = "21,060";
> row1[6] = "24,570";
> row1[7] = "7,020";
> row1[8] = "9,360";
> row1[9] = "11,700";
> row1[10] = "14,040";
> row1[11] = "16,380";
> dt1.Rows.Add(row1);
> DataRow row2 = dt1.NewRow();
> row2[0] = "Boston Mutual";
> row2[1] = "Renewal 7%";
> row2[2] = "819";
> row2[3] = "1,092";
> row2[4] = "1,365";
> row2[5] = "1,638";
> row2[6] = "1,911";
> row2[7] = "546";
> row2[8] = "728";
> row2[9] = "910";
> row2[10] = "1,092";
> row2[11] = "1,274";
> dt1.Rows.Add(row2);
> DataRow row3 = dt1.NewRow();
> row3[0] = "Boston Mutual";
> row3[1] = "First Year 90%";
> row3[2] = "10,530";
> row3[3] = "14,040";
> row3[4] = "17,550";
> row3[5] = "21,060";
> row3[6] = "24,570";
> row3[7] = "7,020";
> row3[8] = "9,360";
> row3[9] = "11,700";
> row3[10] = "14,040";
> row3[11] = "16,380";
> dt1.Rows.Add(row3);
> DataRow row4 = dt1.NewRow();
> row4[0] = "Boston Mutual";
> row4[1] = "Renewal 7%";
> row4[2] = "819";
> row4[3] = "1,092";
> row4[4] = "1,365";
> row4[5] = "1,638";
> row4[6] = "1,911";
> row4[7] = "546";
> row4[8] = "728";
> row4[9] = "910";
> row4[10] = "1,092";
> row4[11] = "1,274";
> dt1.Rows.Add(row4);
> ds.Tables.Add(dt1);
> this.rptCommissionTable.DataSource = ds;
> this.rptCommissionTable.DataBind();
> }
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form
> Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Load += new System.EventHandler(this.Page_Load);
> }
> #endregion
> protected void rptCommissionTable_ItemDataBound(object sender,
> System.Web.UI.WebControls.RepeaterItemEventArgs e)
> {
> DataRowView data = (DataRowView)e.Item.DataItem;
> if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> ListItemType.AlternatingItem)
> {
> if(this.commisionTableRowCount % 2 == 0)
> {
> //e.Item.Controls.RemoveAt(2);
> }
> else
> {
> HtmlTableCell carrierCell = new HtmlTableCell();
> GlobalRadioButton grb = new GlobalRadioButton();
> grb.Text = data["Carrier"].ToString();
> grb.GroupName = this.ID + "_radiogroup";
> carrierCell.RowSpan = 2;
> carrierCell.Controls.Add(grb);
> //carrierCell.InnerText = data["Carrier"].ToString();
>
> ((HtmlTableRow)e.Item.Controls[1]).Cells.Insert(0,carrierCell);
> }
> ((Label)e.Item.FindControl("lblCompensationSchedul e")).Text =
> data["CompensationSchedule"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorARate1")).Te xt =
> data["AdvisorARate1"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorARate2")).Te xt =
> data["AdvisorARate2"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorARate3")).Te xt =
> data["AdvisorARate3"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorARate4")).Te xt =
> data["AdvisorARate4"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorARate5")).Te xt =
> data["AdvisorARate5"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorBRate1")).Te xt =
> data["AdvisorBRate1"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorBRate2")).Te xt =
> data["AdvisorBRate2"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorBRate3")).Te xt =
> data["AdvisorBRate3"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorBRate4")).Te xt =
> data["AdvisorBRate4"].ToString();
> ((Label)e.Item.FindControl("lblAdvisorBRate5")).Te xt =
> data["AdvisorBRate5"].ToString();
> this.commisionTableRowCount++;
> }
> }
> }
> }
> Thanks for the help
>




 
Reply With Quote
 
John Teague
Guest
Posts: n/a
 
      03-21-2005
Thanks for looking into it.

I tried commenting those out with no luck. The page works fine when it's
declared as a aspx page. The issue occurs when I try to use it as an ascx
page.

Thanks,
John

"Brock Allen" wrote:

> Well, I copied this code into a ASPX and did two things:
>
> 1) Called BindCommissionRepeater() from Page_Load
> 2) Commented out the references to GlobalRadioButton
>
> And it worked fine. I'm not sure what the real problem is then
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > The answer is yes to both of your questions. My code has been review
> > by other developers and nothing was glarringly wrong with the code (at
> > least to us .
> >
> > Here is the repeater tag:
> > <asp:repeater id=rptCommissionTable runat="server"
> > OnItemDataBound="rptCommissionTable_ItemDataBound" >
> > <HeaderTemplate>
> > <table border="1" cellpadding="0" cellpadding="0">
> > <tr>
> > <td colspan="12">Universal Life</td>
> > </tr>
> > <tr>
> > <td rowspan="3">
> > Carrier
> > </td>
> > <td rowspan="3">Product Compensation Schedule</td>
> > <td colspan="10">Total Commissions as a Function of
> > Penetration
> > Percentage</td>
> > </tr>
> > <tr>
> > <td colspan="5">Advisor A</td>
> > <td colspan="5">Advisor B</td>
> > </tr>
> > <tr>
> > <td>30%</td>
> > <td>40%</td>
> > <td>50%</td>
> > <td>60%</td>
> > <td>70%</td>
> > <td>30%</td>
> > <td>40%</td>
> > <td>50%</td>
> > <td>60%</td>
> > <td>70%</td>
> > </tr>
> > </HeaderTemplate>
> > <ItemTemplate>
> > <tr runat="server">
> > <td>
> > <asp:Label ID="lblCompensationSchedule"
> > Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorARate1" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorARate2" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorARate3" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorARate4" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorARate5" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorBRate1" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorBRate2" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorBRate3" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorBRate4" Runat="server"></asp:Label>
> > </td>
> > <td>
> > <asp:Label ID="lblAdvisorBRate5" Runat="server"></asp:Label>
> > </td>
> > </tr>
> > </ItemTemplate>
> > <FooterTemplate>
> > </table>
> > </FooterTemplate>
> > </asp:Repeater>
> > and the current codebehind (I have changed this many times to find the
> > problem)
> >
> > namespace NFP.Benefits.VoluntaryBenefits.Commissions
> > {
> > /// <summary>
> > /// Summary description for VBCommissionMatrix.
> > /// </summary>
> > public class VBCommissionMatrix : System.Web.UI.UserControl
> > {
> > protected MetaBuilders.WebControls.GlobalRadioButton rb = new
> > GlobalRadioButton();
> > protected System.Web.UI.WebControls.Repeater rptCommissionTable;
> > protected Label lblTest;
> > private int commisionTableRowCount = 1;
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > // Put user code to initialize the page here
> > }
> > protected override void OnPreRender(EventArgs e)
> > {
> > base.OnPreRender (e);
> > }
> > private void BindCommissionRepeater()
> > {
> > DataSet ds = new DataSet();
> > DataTable dt1 = new DataTable();
> > dt1.Columns.Add("Carrier");
> > dt1.Columns.Add("CompensationSchedule");
> > dt1.Columns.Add("AdvisorARate1");
> > dt1.Columns.Add("AdvisorARate2");
> > dt1.Columns.Add("AdvisorARate3");
> > dt1.Columns.Add("AdvisorARate4");
> > dt1.Columns.Add("AdvisorARate5");
> > dt1.Columns.Add("AdvisorBRate1");
> > dt1.Columns.Add("AdvisorBRate2");
> > dt1.Columns.Add("AdvisorBRate3");
> > dt1.Columns.Add("AdvisorBRate4");
> > dt1.Columns.Add("AdvisorBRate5");
> > DataRow row1 = dt1.NewRow();
> > row1[0] = "Boston Mutual";
> > row1[1] = "First Year 90%";
> > row1[2] = "10,530";
> > row1[3] = "14,040";
> > row1[4] = "17,550";
> > row1[5] = "21,060";
> > row1[6] = "24,570";
> > row1[7] = "7,020";
> > row1[8] = "9,360";
> > row1[9] = "11,700";
> > row1[10] = "14,040";
> > row1[11] = "16,380";
> > dt1.Rows.Add(row1);
> > DataRow row2 = dt1.NewRow();
> > row2[0] = "Boston Mutual";
> > row2[1] = "Renewal 7%";
> > row2[2] = "819";
> > row2[3] = "1,092";
> > row2[4] = "1,365";
> > row2[5] = "1,638";
> > row2[6] = "1,911";
> > row2[7] = "546";
> > row2[8] = "728";
> > row2[9] = "910";
> > row2[10] = "1,092";
> > row2[11] = "1,274";
> > dt1.Rows.Add(row2);
> > DataRow row3 = dt1.NewRow();
> > row3[0] = "Boston Mutual";
> > row3[1] = "First Year 90%";
> > row3[2] = "10,530";
> > row3[3] = "14,040";
> > row3[4] = "17,550";
> > row3[5] = "21,060";
> > row3[6] = "24,570";
> > row3[7] = "7,020";
> > row3[8] = "9,360";
> > row3[9] = "11,700";
> > row3[10] = "14,040";
> > row3[11] = "16,380";
> > dt1.Rows.Add(row3);
> > DataRow row4 = dt1.NewRow();
> > row4[0] = "Boston Mutual";
> > row4[1] = "Renewal 7%";
> > row4[2] = "819";
> > row4[3] = "1,092";
> > row4[4] = "1,365";
> > row4[5] = "1,638";
> > row4[6] = "1,911";
> > row4[7] = "546";
> > row4[8] = "728";
> > row4[9] = "910";
> > row4[10] = "1,092";
> > row4[11] = "1,274";
> > dt1.Rows.Add(row4);
> > ds.Tables.Add(dt1);
> > this.rptCommissionTable.DataSource = ds;
> > this.rptCommissionTable.DataBind();
> > }
> > #region Web Form Designer generated code
> > override protected void OnInit(EventArgs e)
> > {
> > //
> > // CODEGEN: This call is required by the ASP.NET Web Form
> > Designer.
> > //
> > InitializeComponent();
> > base.OnInit(e);
> > }
> >
> > /// <summary>
> > /// Required method for Designer support - do not modify
> > /// the contents of this method with the code editor.
> > /// </summary>
> > private void InitializeComponent()
> > {
> > this.Load += new System.EventHandler(this.Page_Load);
> > }
> > #endregion
> > protected void rptCommissionTable_ItemDataBound(object sender,
> > System.Web.UI.WebControls.RepeaterItemEventArgs e)
> > {
> > DataRowView data = (DataRowView)e.Item.DataItem;
> > if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> > ListItemType.AlternatingItem)
> > {
> > if(this.commisionTableRowCount % 2 == 0)
> > {
> > //e.Item.Controls.RemoveAt(2);
> > }
> > else
> > {
> > HtmlTableCell carrierCell = new HtmlTableCell();
> > GlobalRadioButton grb = new GlobalRadioButton();
> > grb.Text = data["Carrier"].ToString();
> > grb.GroupName = this.ID + "_radiogroup";
> > carrierCell.RowSpan = 2;
> > carrierCell.Controls.Add(grb);
> > //carrierCell.InnerText = data["Carrier"].ToString();
> >
> > ((HtmlTableRow)e.Item.Controls[1]).Cells.Insert(0,carrierCell);
> > }
> > ((Label)e.Item.FindControl("lblCompensationSchedul e")).Text =
> > data["CompensationSchedule"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorARate1")).Te xt =
> > data["AdvisorARate1"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorARate2")).Te xt =
> > data["AdvisorARate2"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorARate3")).Te xt =
> > data["AdvisorARate3"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorARate4")).Te xt =
> > data["AdvisorARate4"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorARate5")).Te xt =
> > data["AdvisorARate5"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorBRate1")).Te xt =
> > data["AdvisorBRate1"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorBRate2")).Te xt =
> > data["AdvisorBRate2"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorBRate3")).Te xt =
> > data["AdvisorBRate3"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorBRate4")).Te xt =
> > data["AdvisorBRate4"].ToString();
> > ((Label)e.Item.FindControl("lblAdvisorBRate5")).Te xt =
> > data["AdvisorBRate5"].ToString();
> > this.commisionTableRowCount++;
> > }
> > }
> > }
> > }
> > Thanks for the help
> >

>
>
>
>

 
Reply With Quote
 
John Teague
Guest
Posts: n/a
 
      03-21-2005
Ok, I solved the problem. I wanted to confirm that I have reasonably
explained why this happened.

What made it work was changing the Register tag to use the source property.
Originally, I had

<%@ Register TagPrefix="nfp2" Namespace="VBComparisonMatrix.WebUserControl"
Assembly="VBCommissionMatrix" %>

When I changed it to:

<%@ Register TagPrefix="uc2" TagName="VBCommissionMatrix"
Src="VBCommissionMatrix.ascx" %>

It worked.

The reason I think the src property is the key is because the JIT handles
everything that I had created on the ascx page that wasn't instantiated in
the code behind. The first directive only gave the JIT the dll and didn't
know there was anything else to do. Once I have it the source page, it found
the repeater and instantiated it.

Let me know if you think this is correct.

Thanks for your help.
John

"John Teague" wrote:

> am building a user control that has a repeater in it. I first started with a
> regular web page to get the formatting right where everything worked
> properly. I then copied it into a new ascx file.
>
> The repeater is created on the page (not dynamic). I have a function that
> databinds the repeater:
>
> private void BindRepeater(){
> DataSet ds = new DataSet();
> . . . create dataset structure . . .;
>
> repeater.datasource = ds; //error occurs here
> repeater.Databind();
> }
>
> I get an error message that object reference not set to an instance. When I
> step through with the debugger, the repeater is not instantiated.
>
> This only happened after I moved it to an ascx page and put the control on
> an aspx page. I have tried calling this function in the page_load, init, and
> prerender.
>
> Any suggestions?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python 3 - instantiating class from user input Brad Bailey Python 1 04-07-2011 06:50 AM
Instantiating control instances - VS2005 Websites David Rees ASP .Net 1 12-10-2006 10:43 PM
instantiating a template control Andy Fish ASP .Net 3 04-01-2005 02:45 PM
Dynamically instantiating a statically defined custom web control Rahul Mittal ASP .Net Web Controls 1 10-19-2003 05:54 AM
Re: How to keep User Control from instantiating Mike Fors ASP .Net 2 08-27-2003 07:06 PM



Advertisments