|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Article Discussion: Easy ASP.NET Page Templates
Easy ASP.NET Page Templates If you have any questions or comments about this article then please post them here.
You can read the article here . |
|
#2
|
|||
|
|||
|
Problem found.
In case no-one knows who I am I'm the guy who wrote this article.
There was something I hadn't realised. ViewState doesn't get loaded for controls on the page if you build these controls in the CreateChildControls event. The LoadViewState method of each control runs just after initialization, the CreateChildControls method runs long after that, therefore the controls on the page pretty much don't exist when LoadViewState is executed. The fix for this is to create all controls on the page in your constructor, which is executed before anything else on the page. But when finding and adding the page specific controls (called "Main" in the article) you will need to do this after the Init event, so you can override the OnInit(EventArgs e) method and do it there if you like. Hope this helps solve some problems. Cheers, John Rebbeck |
|
#3
|
|||
|
|||
|
The Main object is always rendering before my Header section. I used the same code as provided in the article and modified it using your forum message. Any ideas?
![]() |
|
#4
|
|||
|
|||
|
well, i really liked that artile until i didn't have to use templates in asp.net on my own.
unfortunately the method described there has imho a clash in the basic design: template technique cannot be just after System.Web.UI.Page (i'm referring to the first figure in the doc), it should be somewhere between "Page Code-behind class" and "ASPX Page". please read further about it at: URL it clearly claims in one of paragraphs: Quote:
so, does anybody knows such solution for asp.net? i mean something which allows to define presentation layer independently to the code-behind class. to prepare something like "visual snippets" where logic could be defined once by a programmer in the typical .net class and visible form could be edited by a designer to provide e.g. FancyForm, or ReportsTable pseudo-class which is defined in the language similar to the HTML or so. Last edited by bonkey : February 16th, 2003 at 12:55 PM. |
|
#5
|
|||
|
|||
|
Hm... isn't the code-behind class part of the presentation layer?
![]() |
|
#6
|
|||
|
|||
|
Make an abstract Control property in the base class that the derived class must implement and refer to that in your base class rather than finding one based on name (too tightly coupled). Or just cycle through the controls in the base class and add them to the form in the base class
'sorry! i'm forced to program in vb.net now... Dim count As Integer = Me.Controls.Count - 1 Dim i As Integer For i = 0 To count Dim ctl As Control = Me.Controls(0) form.Controls.Add(ctl) Me.Controls.Remove(ctl) Next |
|
#7
|
|||
|
|||
|
Re: Problem found. And another...
I also noticed the problem with CreateChildControls and also found that overriding the OnInit event fixed this.
There is another problem however. If you have UserControls in you page (within the "Main" panel) these UserControls get processed twice. This is a problem if the UserControl makes database calls and fills a list etc. 2 database calls instead of one every time the page loads not so good. To test this simply place a UserControl into a templated page and put a break on the OnLoad event for the UserControl. I have spent a reasonable amount of time trying to overcome this problem but have only found two solutions that are not all that good: 1. Code all UserControls to check whether they have already been processed, and process accordingly. 2. Include the <form> tag on you templated page and do not explicitly add any sections to your template using the basepage. This will then rely on the render event to simply render the content in the .aspx file. What this also means is that you can only have one section and really negates a lot of the benefit of using templates. If you have any ideas on how to solve this problem I would be most interested in hearing them. Cheers Nathan Quote:
|
|
#8
|
|||
|
|||
|
missing attribute in example template
This template page was missing the runat="server" attribute in the panel elements. This caused me some delay in understanding what was going on. (I do wish that the author would upload working examples of their code!!!)
|
|
#9
|
|||
|
|||
|
Additional quick fix to ViewState problem
As the author suggested, the controls need to be created inside the OnInit() method.
An easy way to do this is to: Protected Overrides Sub OnInit(ByVal e As System.EventArgs) EnsureChildControls() End Sub Juraj I wasted two hours looking for this view state bug, and only then saw the author's original article correction. |
|
#10
|
|||
|
|||
|
How about some VB.NET sample code for templates?
-- Down with C# -- |
|
#11
|
|||
|
|||
|
well, there is another article where may shed some light.
http://www.devx.com/dotnet/Article/18011/0/ and I think to stop the parsing you might need to use [ParseChildren(false)] see how it's being used on this other article |
|
#12
|
|||
|
|||
|
Validation Controls not working
I've followed the correction that was given by the author and everything seems to be working except my validation controls doesn't seem to be causing any client side validation.
Anyone else experiencing this problem??? Thanks. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Article Discussion: Easy ASP.NET Page Templates |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|