473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataBinding lost of Postback

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.");
}
}
Jul 12 '07 #1
1 2134
nateraaaa
663 Expert 512MB
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.");
}
}
Try storing the value of your InterationString in a Session variable. This should eliminate your problem of losing the InterationString value on a postback.

Nathan
Jul 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Lloyd Sheen | last post by:
I have several apps that use a roll your own approach, but I am embarking on a project which will not allow that with the time constraints. I have gened up a little app to try the databinding...
10
by: Krista Lemieux | last post by:
I'm new to ASP.NET and I'm not use to the way things are handled with this technology. I've been told that when I have a control, I should only bind the data to it once, and not on each post back...
3
by: Ross Holder | last post by:
Am trying to bind a textbox ASP.NET web control to an UPDATE stored proc in the codebehind and can't seem to get it working. I'm using a dataview, which a SELECT stored proc populates in the...
3
by: Stan | last post by:
I am looking for the best solution for this scenario: ASP.NET needs display an editable form with 20 textboxes. Data source is xml. Xml must be updated. if user clicks Update button on the form....
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
9
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
9
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables...
4
by: Frank | last post by:
Hello everyone, I have a problem that the window.opener variable is lost once my popup page has a postback. On multiple pages they address this problem but I cannot find a correct answer. ...
2
by: Sebastian | last post by:
Hi, I want to skin the templates of an asp:DataList. So I have to do data binding in the skin (I didn't find another comfortable way to do that). As soon there's a <%# ... %tag in the skin, VS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.