473,796 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:

_myTemplateCont ainer = New ContentContaine r(Me)
ContentTemplate .InstantiateIn( _myTemplateCont ainer)
Controls.Add(_m yTemplateContai ner)

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)
_myTemplateCont ainer = New ContentContaine r(Me)
ContentTemplate .InstantiateIn( _myTemplateCont ainer)
_myTemplateCont ainer.RenderCon trol(htmlTW)

If Not Me.Page.IsClien tScriptBlockReg istered("MainWi ndow_" & Me.ID) Then
Me.Page.Registe rClientScriptBl ock("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 2961
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**********@z ywave.com> wrote in message
news:uF******** ******@tk2msftn gp13.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:

_myTemplateCont ainer = New ContentContaine r(Me)
ContentTemplate .InstantiateIn( _myTemplateCont ainer)
Controls.Add(_m yTemplateContai ner)

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)
_myTemplateCont ainer = New ContentContaine r(Me)
ContentTemplate .InstantiateIn( _myTemplateCont ainer)
_myTemplateCont ainer.RenderCon trol(htmlTW)

If Not Me.Page.IsClien tScriptBlockReg istered("MainWi ndow_" & Me.ID) Then
Me.Page.Registe rClientScriptBl ock("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
1471
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 a custom typed collection inherited from IList I get an error when parsing: Ligne 4 : <br> Ligne 5 : <galador:SelectPanel runat="server" id="SelectPanel1"> Ligne 6 : <Panels>
19
2990
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 provide an open TD with a DIV in it for the content of this formlet. (The DIV is for DHTML to hide and show the content) I've created a web page showing step by step the two problems I'm encountering. This problem is much easier to see than it...
0
357
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 following reasons: 1) Render blocks are not allowed inside a templated control. 2) I want the inner controls scoped at the parent aspx (or ascx), not at the template naming container. This type of control would be ideal for website headers and...
2
1451
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 directly accessed from the code behind. In the code listing below, trying to use "Literal1" control in the code behind results in a null reference exception. How do I make the controls within my templated custom control accessible in the code...
21
2106
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 string with comma delimited values. For example, if I were to render two text boxes. One with the Value Terry and the Other with the Value 'Burns' I would get the following value Terry,Burns.
1
3238
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 CompositeControl/CompositeControlDesigner to have and Action or Verb in the control's smart tag titled 'Convert to Template' which actually converts the whole control, including it's child controls to templated mode. Do this in the Login control, and you'll see...
0
1607
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 correctly. If I change to HTML the generated html is <cc1:IT24DateTime id="IT24DateTime1" runat="server" Type="Date"></cc1:IT24DateTime> .... and that works correctly.
11
3289
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: <my:RoundedCornerBox id=foo runat=server>
2
1435
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 control for and possibly email a zip file with that control so I could run it in a program to see how it worked? to pts4560 <atyahoo.com ? thanks.
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10244
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.