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

Custom Templated Control not rendering asp.net controls correctly

If I have an ASP.net button inside a template for a custom control and use
the code below, everything works fine and it generates the correct id and
the asp.net button calls serverside click event as it should:

_myTemplateContainer = New ContentContainer(Me)
ContentTemplate.InstantiateIn(_myTemplateContainer )
Controls.Add(_myTemplateContainer)

But if I use this code, it does not generate the unique ID and no serverside
event will be called:
Dim SB As New StringBuilder()
Dim SW As New StringWriter(SB)
Dim htmlTW As New HtmlTextWriter(SW)
_myTemplateContainer = New ContentContainer(Me)
ContentTemplate.InstantiateIn(_myTemplateContainer )
_myTemplateContainer.RenderControl(htmlTW)

If Not Me.Page.IsClientScriptBlockRegistered("MainWindow_ " & Me.ID) Then
Me.Page.RegisterClientScriptBlock("MainWindow_" & Me.ID, SB.ToString)
End If

The reason I was trying to do it this way is because I need the html of the
template and some other html table code to be output to the top of the html
page no matter where the actual custom control is sited and this was the
only way I could figure out how to do that.

Do you happen to know either of these answers:

1. Is there something else I need to do to get RenderControl to generate
proper ID's for asp.net control that exist on the template I am trying to
render or is that just not possible.
2. Is there another way I can make sure the output of the template always
appears at the top of the page html?
Nov 19 '05 #1
1 2945
Hi,

on the second code block, you don't add the template container to the
Controls collection, that's the key part in when Page generates IDs for
controls or when events are handled (for postback events, control would need
to be in Controls collection at Page_Load at the latest)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"news.microsoft.com" <ki**********@zywave.com> wrote in message
news:uF**************@tk2msftngp13.phx.gbl...
If I have an ASP.net button inside a template for a custom control and use
the code below, everything works fine and it generates the correct id and
the asp.net button calls serverside click event as it should:

_myTemplateContainer = New ContentContainer(Me)
ContentTemplate.InstantiateIn(_myTemplateContainer )
Controls.Add(_myTemplateContainer)

But if I use this code, it does not generate the unique ID and no
serverside event will be called:
Dim SB As New StringBuilder()
Dim SW As New StringWriter(SB)
Dim htmlTW As New HtmlTextWriter(SW)
_myTemplateContainer = New ContentContainer(Me)
ContentTemplate.InstantiateIn(_myTemplateContainer )
_myTemplateContainer.RenderControl(htmlTW)

If Not Me.Page.IsClientScriptBlockRegistered("MainWindow_ " & Me.ID) Then
Me.Page.RegisterClientScriptBlock("MainWindow_" & Me.ID, SB.ToString)
End If

The reason I was trying to do it this way is because I need the html of
the template and some other html table code to be output to the top of the
html page no matter where the actual custom control is sited and this was
the only way I could figure out how to do that.

Do you happen to know either of these answers:

1. Is there something else I need to do to get RenderControl to generate
proper ID's for asp.net control that exist on the template I am trying to
render or is that just not possible.
2. Is there another way I can make sure the output of the template always
appears at the top of the page html?

Nov 19 '05 #2

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

Similar topics

0
by: Lloyd Dupont | last post by:
I'm trying to create a templated custom control which hold a collection of something else in his property 'Panels' when this property is of type ArrayList it parse ok. however when I try to use...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
0
by: John Crowley | last post by:
I keep running into this over and over again... I want a block server control that renders a header and footer, and child controls in between. But I don't want a templated control, for the...
2
by: Earl Teigrob | last post by:
I have created a simple custom control that uses a table to create space around its contents. The code in the aspx page is show below. My problem is that the controls within the template can not be...
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
1
by: Andrew Clancy | last post by:
Hi, Myself and a colleague are attempting to mimic the custom template functionality of the ASP.Net 2 Login control. Essentially, we would like to have the ability within our...
0
by: pabloazorin | last post by:
I developed a Date Picker web control using C# and .net framework 1.1 I added my control to Visual Studio 2003 IDE toolbar. When I drag and drop my control to design web page, the control renders...
11
by: Nick Gilbert | last post by:
Hi, How can I create a custom control which will wrap its content in a header and footer? eg: Is it possible to create a .NET user control which can surround other controls? eg:...
2
by: Ron | last post by:
I would like some more information on custom controls, what they can do and things like that, what you would use them for etc... Can anyone here share some examples of what you have used a custom...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.