473,386 Members | 1,705 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,386 software developers and data experts.

Embedded User Control in DataList - Postback Issue

I feel like I'm going to pull out my hair (there's not much left); I've
read almost every online post trying to figure this out. So I started
over with something VERY simple and it still doesn't work ... here we
go. I have a datalist with an embedded user control. My user control
outputs a single string. The first time thru, everything works
perfectly ... on a postback, the datalist gets it's values correctly,
but the user control does NOT get a passed in value ... here is my test
code; it can't be much simpler (I know that this has to do something
with the ordering of events).

-- TestClass.ascx --
<%@ Control Language="VB" AutoEventWireup="false" ClassName="TestClass"
%>
<script language="VB" runat="server">
Public MyString As String
Private Sub Page_Load(ByVal src As Object, ByVal e As EventArgs)
Handles MyBase.Load
Response.Write(MyString)
End Sub
</script>

-- TestPage.aspx --
<%@ Page Language="VB" AutoEventWireup="false" Trace="true"%>
<%@ Register TagPrefix="MyTest" TagName="TestClass"
Src="TestClass.ascx" %><html>
<head runat="server">
<script language="VB" runat="server">
Sub Page_Load(ByVal src As Object, ByVal e As EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
Dim dt As New System.Data.DataTable
dt.Columns.Add("name")
Dim dr As System.Data.DataRow
dr = dt.NewRow
dr.Item(0) = "First Run"
dt.Rows.Add(dr)
dg.DataSource = dt
dg.DataBind()
End If
End Sub
Sub linkBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
Trace.Warn("Clicked Button Event")
Dim dt As New System.Data.DataTable
dt.Columns.Add("name")
Dim dr As System.Data.DataRow
dr = dt.NewRow
dr.Item(0) = "Second Run"
dt.Rows.Add(dr)
dg.DataSource = dt
dg.DataBind()
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:LinkButton ID="linkBtn" runat="server"
OnClick="linkBtn_Click">Click</asp:LinkButton>
<asp:DataList ID="dg" runat="server" >
<ItemTemplate>
<%# Container.DataItem("name") %> in datalist
<MyTest:TestClass id="lalala" runat="server" MyString = '<%#
Container.DataItem("name") %>' />
</ItemTemplate>
</asp:DataList>
</form>
</body>
</html>

Can't be much made any more simple ... TestClass takes MyString and
spits it out to Response.Write. Problem:
1) On first run, everything works perfectly
2) Click the "Click" button
3) I get my "Second Run in datalist" line, but MyString in the user
control isn't being rebound. I know that Container.DataItem HAS a
value and is NOT null.

I don't care about a Viewstate (because I always want to recreate this
control regardless). I don't plan on retrieving any information from
the control (it is just a display control, I'd use an include file like
in PHP or HTML if I could ... we are trying to modularize code rather
than have 1000+ lines in one file)

Please can anyone help!!!!

Rick

Mar 17 '06 #1
0 1545

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mary Kerrigan | last post by:
I have a user control (menu) with a data list: <asp:DataList id="MyList" runat="server"> <ItemTemplate> <asp:hyperlink cssclass="MenuUnselected" id="myLink1" Text='<%#...
1
by: wsyeager36 | last post by:
I have a datagrid inside a datalist. The datalist shows parent info and the datagrid shows the child info for that parent. There is a checkbox on each row of the child datagrid. Also inside the...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
2
by: Roman | last post by:
I have built a simple user control that contains 2 buttons, a text box and a dropdownlist. When a button is clicked it sets the visible property of the textbox/dropdownlist and the button. ie the...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
1
by: yoknows | last post by:
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...
0
by: John Smith | last post by:
I still have not gotten this damn thing figured out and I'm asking for help one last time before I give up on it. I have a user control that contains a paged gridview control. The master page...
1
by: Maury | last post by:
Hello, I created two user control, the first manage an object of mine, the second is a DataList in which each Item is the first control...when I click the 'save' button in the first control, the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.