[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

User Control Template Not Working

I am trying to create a user control that allows the use of a template to show the data.

But I get no data displayed when I use

<ItemTemplate>Test:<%# Container.ItemId %></ItemTemplate>

If I do not create the template.... I do see the "template not defined" error as expected.

I have attached the files that I am using to demonstrate my problem.
Default2.aspx.cs.txt
Default2.aspx.txt
WebUserControl.ascx.cs.txt
WebUserControl.ascx.txt
0
spencerturbine
Asked:
spencerturbine
1 Solution
 
ppittleCommented:
spencerturbine,

Two theories:

1) The Default2.aspx needs to manually call WebUserCall1.DataBind() method.  For some reason, I think if you do not declartively set either DataSourceID or DataSource properties the DataBind method is not called by the ASP.NET Page LifeCycle and you'll need to manually call the DataBind method.  You can safely call WebUserCall1.DataBind() from the Default2 PageLoad event handler.

2) The WebUserControl.ascx OnInit() event is fired before the ItemID property is set.  Try using the OnLoad or OnDataBind event instead.

Let me know if that works for you.

PJ
0
 
spencerturbineAuthor Commented:
Databind worked like a charm!

Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now