Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 29th, 2002, 10:09 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 589 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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 .

Reply With Quote
  #2  
Old January 11th, 2003, 01:30 AM
Vantera Vantera is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: South Coast of NSW, Australia
Posts: 108 Vantera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Vantera
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

Reply With Quote
  #3  
Old February 15th, 2003, 12:00 PM
mrcode925 mrcode925 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 1 mrcode925 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Main section always redered first?

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?

Reply With Quote
  #4  
Old February 16th, 2003, 12:45 PM
bonkey bonkey is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 1 bonkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation bad design

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:
In other words, it is strictly forbidden to refer to the presentation layer when you are in the service layer

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.

Reply With Quote
  #5  
Old April 16th, 2003, 12:24 PM
bobsmith bobsmith is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 bobsmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hm... isn't the code-behind class part of the presentation layer?

Reply With Quote
  #6  
Old April 23rd, 2003, 09:28 PM
pjwal pjwal is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 pjwal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #7  
Old May 18th, 2003, 07:27 PM
nathanl nathanl is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 1 nathanl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
Originally posted by Vantera
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

Reply With Quote
  #8  
Old May 23rd, 2003, 06:07 PM
jlb0001 jlb0001 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 1 jlb0001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!!!)

Reply With Quote
  #9  
Old December 10th, 2003, 11:51 PM
hansolo_jp hansolo_jp is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 hansolo_jp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #10  
Old March 2nd, 2004, 02:04 PM
bostonnole bostonnole is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Boston MA
Posts: 1 bostonnole User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How about some VB.NET sample code for templates?





-- Down with C# --

Reply With Quote
  #11  
Old June 3rd, 2004, 04:01 PM
windust windust is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 windust User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #12  
Old July 26th, 2004, 07:52 AM
h0wie h0wie is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 h0wie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Article Discussion: Easy ASP.NET Page Templates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT