Y
yoknows
Hello .Net Gurus. This is my first post here so I apologize in advance
if I have not provided the right information. I hope someone has seen
this problem before and can tell me what I am doing wrong. I have
simplified the problem with the following example:
Using asp.net 2.0, I have a Master page template used on default.aspx.
control has a checkbox with OnChanged event firing a postback.
The problem is on postback to default.aspx, I need to know the state of
the Checkbox that was clicked on in the "Inner" user control. Alas,
the value is always FALSE. Only when the User control's OnChanged
event executes, do I see the new value.
When I do this without a Master page, it works as expected, and I can
see the new value of the Checkbox at the Page_Load of the default.aspx.
Any ideas what I am doing wrong here? (Thanks)
The code below is from default.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default"
MasterPageFile="~/templates/eDonations.master" %>
<%@ Register Src="inner.ascx" TagName="inner" TagPrefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<aspataList ID="DataList1" runat="server">
<ItemTemplate>
<uc2:inner id="Inner1" runat="server" Name=<%#
Container.DataItem %> >
</uc2:inner>
</ItemTemplate>
</aspataList>
</ASP:Content>
---------------------------------------
And here is the Code behind:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList list = new ArrayList();
list.Add("1");
list.Add("2");
DataList1.DataSource = list;
DataList1.DataBind();
}
else
{
inner _inItem = new inner();
int ItemIndex = 0;
foreach (DataListItem _item in DataList1.Items)
{
++ItemIndex;
_inItem = (inner)_item.FindControl("inner1");
string hello = _inItem.Name;
CheckBox chk =
(CheckBox)_inItem.FindControl("Checkbox1");
if (chk.Checked)
{
//Do something
}
}
}
}
}
if I have not provided the right information. I hope someone has seen
this problem before and can tell me what I am doing wrong. I have
simplified the problem with the following example:
Using asp.net 2.0, I have a Master page template used on default.aspx.
iterating a User control "Inner" with one property, Name. The userFrom within the Content tags on that page I placed a Datalist. It is
control has a checkbox with OnChanged event firing a postback.
The problem is on postback to default.aspx, I need to know the state of
the Checkbox that was clicked on in the "Inner" user control. Alas,
the value is always FALSE. Only when the User control's OnChanged
event executes, do I see the new value.
When I do this without a Master page, it works as expected, and I can
see the new value of the Checkbox at the Page_Load of the default.aspx.
Any ideas what I am doing wrong here? (Thanks)
The code below is from default.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default"
MasterPageFile="~/templates/eDonations.master" %>
<%@ Register Src="inner.ascx" TagName="inner" TagPrefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<aspataList ID="DataList1" runat="server">
<ItemTemplate>
<uc2:inner id="Inner1" runat="server" Name=<%#
Container.DataItem %> >
</uc2:inner>
</ItemTemplate>
</aspataList>
</ASP:Content>
---------------------------------------
And here is the Code behind:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList list = new ArrayList();
list.Add("1");
list.Add("2");
DataList1.DataSource = list;
DataList1.DataBind();
}
else
{
inner _inItem = new inner();
int ItemIndex = 0;
foreach (DataListItem _item in DataList1.Items)
{
++ItemIndex;
_inItem = (inner)_item.FindControl("inner1");
string hello = _inItem.Name;
CheckBox chk =
(CheckBox)_inItem.FindControl("Checkbox1");
if (chk.Checked)
{
//Do something
}
}
}
}
}