I have a stupid problem but not able to find solution :(
I have repeater that create user control (WebUserControl1) . I pass parameter (InterationString) to user control that is "Container.DataItem" of repeater.
When Usercontrol postback page (autopostback=true on dropdownlist), UserControl lose parameter value. InterationString is correctly set on first loading but on postback, IterationString property is null.
Thank for your help.
Here is the code :
******************************** Web Page ************************************
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<%@ Register Src="WebUserControl1.ascx" TagName="WebUserControl1" TagPrefix="uc1" %>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater runat="server" ID="repeater1" DataSource="<%# GetSource %>">
<ItemTemplate>
<uc1:WebUserControl1 id="WebUserControl1_1" InterationString='<%# Container.DataItem %>' runat="server">
</uc1:WebUserControl1>
<br /><br />
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
this.DataBind();
}
public string[] GetSource
{
get { return new string[] { "Iteration 1","Iteration 2" }; }
}
}
******************************** User Control ************************************
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<%= InterationString %> => <asp:DropDownList runat=server ID="ddlAssets" AutoPostBack="true" OnSelectedIndexChanged="ddlAssets_OnSelectedIndexC hanged">
<asp:ListItem Value="1" Text="Test 1"></asp:ListItem>
<asp:ListItem Value="2" Text="Test 2"></asp:ListItem>
</asp:DropDownList>
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string InterationString;
protected void ddlAssets_OnSelectedIndexChanged(object sender, EventArgs args)
{
Response.Write("Event catched.");
}
}