473,407 Members | 2,314 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,407 software developers and data experts.

Help with UserControl

Hello there,

I have inserted a UserControl within a DataList:

/*------------------------------------------------------------*/
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<uc1:WebUserControl ID="WebUserControl1" Title="My Title" runat="server" />
</ItemTemplate>
/*------------------------------------------------------------*/

The User Control is very simple, it only has a Literal control:

/*------------------------------------------------------------*/
public partial class WebUserControl : System.Web.UI.UserControl
{
string title = "Untitled";

public string Title
{
get
{
return title;
}

set
{
title = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
Literal1.Text = title;
}
}
/*------------------------------------------------------------*/

This works just fine, I see "My title" rendered for each Item in the
DataList, however:

/*------------------------------------------------------------*/
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<uc1:WebUserControl ID="WebUserControl1" Title='<%# Eval("Title") %>'
runat="server" />
</ItemTemplate>
/*------------------------------------------------------------*/

This DOESN'T WORK!, all I get is "Untitled" (the default value) :(

I really don't get this behavior and its driving me nuts!

Any ideas?

Edgardo,

PS: I'm using VS 2005 Beta 2
Nov 19 '05 #1
1 1105
Ok, I found out what was my problem, the Page_Load events occurs BEFORE
the Title property is databinded (how stupid!), this is probably because
databinding is done using reflection, so the solution is to override the
OnPreRender event, and do the stuff there:

/*------------------------------------------------------------*/
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
Literal1.Text = Title;
}
/*------------------------------------------------------------*/

And it works just fine.

/me embarrassed

Edgardo Rossetto wrote:
Hello there,

I have inserted a UserControl within a DataList:

/*------------------------------------------------------------*/
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<uc1:WebUserControl ID="WebUserControl1" Title="My Title" runat="server" />
</ItemTemplate>
/*------------------------------------------------------------*/

The User Control is very simple, it only has a Literal control:

/*------------------------------------------------------------*/
public partial class WebUserControl : System.Web.UI.UserControl
{
string title = "Untitled";

public string Title
{
get
{
return title;
}

set
{
title = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
Literal1.Text = title;
}
}
/*------------------------------------------------------------*/

This works just fine, I see "My title" rendered for each Item in the
DataList, however:

/*------------------------------------------------------------*/
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<uc1:WebUserControl ID="WebUserControl1" Title='<%# Eval("Title") %>'
runat="server" />
</ItemTemplate>
/*------------------------------------------------------------*/

This DOESN'T WORK!, all I get is "Untitled" (the default value) :(

I really don't get this behavior and its driving me nuts!

Any ideas?

Edgardo,

PS: I'm using VS 2005 Beta 2

Nov 19 '05 #2

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

Similar topics

2
by: Jose Michael Meo R. Barrido | last post by:
I made a custom runded rectangle usercontrol. I used a function i found on the internet. the function works fine(see "GetRoundRect" below). I use the fullowing code to make my usercontrol...
15
by: Tee | last post by:
Hi, I have a base usercontrol with a method (blank method, no code), I have another few usercontrols that will inherit this base usercontrol, but I want to force all the usercontrol that...
2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
2
by: Lau Lei Cheong | last post by:
Hello, I'm writing a usercontrol that contains a property named "disabled". It is set to false by default but there is also another button in the usercontrol that'll set it to true. On the...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
16
by: Merlin | last post by:
I have created a users control with a text box and button on it, what I want to do is override the usercontrol Keydown events with that of the Text box. What is the correct syntax to accomplish...
22
by: Colin McGuire | last post by:
I apologize for posting yet another scrollbar question. Here is my code. All I want is for a diagonal line to appear from coordinates (0,0) to (width,height) in a usercontrol regardless of whether...
1
by: Philipp Lenz | last post by:
I'm very confused about how this works, all the tutorials out there show me how to apply a skin to a webcontrol, but I want to know how I can access the components of a control....for example: I...
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.