CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!
Free 3 Months



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 4/3/2005 5:09:19 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 2 Views: 53 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
3 Items, 1 Pages 1 |< << Go >> >|
erici
Asp.Net User
Extending the ASP:Literal control4/3/2005 5:09:19 AM

0/0

I've been struggling with what I would assume would be a simple task.  I want to extend the literal control to add a PostStartDate and PostEndDate properties, so the visibility of the control will be easily pre-determined by the current date. 

Obviously I could just use a literal and programatically determine the visibility each time, but I want the HTML developers to just be able to use the control and specify the properties for the start and end dates in the HTML section and have the code handle all the instances in one place.

I've never tried to extend a UC before.  What seems obvious is just inheriting from system.ui.webcontrols.literal and adding on a few date properties.  What isn't obvious to me is how I can make this extended user control accessible from the visual studio environment.  How can I implement this extended control as an optional user control?

Thanks!

Eric

erici
Asp.Net User
Re: Extending the ASP:Literal control4/3/2005 7:53:46 AM

0/0

For those who like to see code, I've included part of the untested class I wrote which I was hoping to somehow register as a user control, since it inherits from the literal webcontrol...

Public Class cExtendedLiteral

Inherits System.Web.UI.WebControls.Literal

Private m_dtPostStartDate As Date = Today

Private m_dtPostEndDate As Date = Now.AddDays(1)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

End Sub

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender

Me.Visible = Me.Visible And (PostStartDate <= Now()) And (PostEndDate >= Now())

End Sub

Public Property PostStartDate() As Date

Get

Return m_dtPostStartDate

End Get

Set(ByVal Value As Date)

m_dtPostStartDate = Value

End Set

End Property

Public Property PostEndDate() As Date

Get

Return m_dtPostEndDate

End Get

Set(ByVal Value As Date)

m_dtPostEndDate = Value

End Set

End Property

End Class

PLBlum
Asp.Net User
Re: Extending the ASP:Literal control4/3/2005 9:33:19 PM

0/0

May I recommend the book: "Developing ASP.NET Server Controls and Components" from Microsoft Press?

Several comments to your class:

1. Avoid using a name as plain as cExtendedLiteral to handle something this specific.

2. The goal of a Literal control is to let you create HTML and assign it to the Text property. You should override the OnPreRender method to assign the property. CustomControls should have any user assigned properties "finalized" in OnPreRender. Its after the user's code edits properties (like your PostStartDate) but before its output (in the Render method).

3. You have selected attaching the event Page_PreRender. Instead of this, override OnPreRender. The event is meant for users to hook up their code. You get the OnPreRender method to handle internal code. Don't forget to call MyBase.OnPreRender() from your method.

4. If you change visibility, do it before calling MyBase.OnPreRender. This is a very special case of custom controls since Visible determines if the PreRender and Render phases run.


--- Peter Blum
Creator of Professional Validation And More Suite, Peter's Date Package, and Peter's Polling Package
www.PeterBlum.com
3 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Expert ASP.NET 2.0 Advanced Application Design: Advanced Application Design Authors: Dominic Selly, Andrew Troelsen, Tom Barnaby, Pages: 459, Published: 2005
Pro ASP.NET 2.0 in C# 2005: Create Next-generation Web Applications with the Latest Version of Microsoft's Revolutionary Technology Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1426, Published: 2006
ASP.NET AJAX Programmer's Reference: With ASP.NET 2.0 Or ASP.NET 3.5 Authors: Shahram Khosravi, Pages: 1522, Published: 2007
Programming ASP.NET: Building Web Applications and Services with ASP.NET 2.0 Authors: Jesse Liberty, Dan Hurwitz, Pages: 930, Published: 2005
Sams Teach Yourself ASP.NET in 21 Days Authors: Chris Payne, Pages: 1104, Published: 2002
Pro ASP.NET 3.5 in C# 2008 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1498, Published: 2007
ASP.NET in a Nutshell: In a Nutshell Authors: G. Andrew Duthie, Matthew MacDonald, Pages: 979, Published: 2003
ASP.NET 2.0: Your Visual Blueprint for Developing Web Applications Authors: Chris Love, Pages: 339, Published: 2007
Professional ASP.NET 2.0 Databases Authors: Thiru Thangarathinam, Pages: 504, Published: 2007

Web:
Extending the ASP:Literal control - ASP.NET Forums Extending the ASP:Literal control. Last post 04-03-2005 5:33 PM by PLBlum. 2 replies. Sort Posts:. Oldest to newest, Newest to oldest ...
Extend ASP.NET: Simplify Data Binding In ASP.NET 2.0 With Our ... Initially, my code used Literal Control insertion to add the dynamic HTML markup into the page .... So go ahead and extend the functionality of what ASP. ...
Valid XHTML within .NET Page and the second will extend System.Web.UI.HtmlControls.HtmlForm . .... Earlier you'll have noticed that we placed an asp:Literal control within the ...
Extending ASP.NET 2.0 Menu Control To Have Tabs With Rounded Corners The ASP.NET Menu Control normally produces tabs which have rectangular edges. The techniques presented extend the control to create tabs with rounded ...
Extending the HtmlForm Control document will concentrate on inheriting and extending the base ASP. .... The code writes an output string to the final asp:Literal control when the form is ...
RemASP @ aspalliance.com ASP.test_aspx. System.Web.UI.LiteralControl. test, System.Web.UI. ... Depending on your needs you can extend both the ControlInfo and the ControlUtil class. ...
How can i use DNN Rich text control - Extend It! ( Programming in ... My gridview has template filed with literal control to display data which ... < asp:Literal ID="Literal1" runat="server" Text='<%# Server. ...
Showing a web page inside a literal control. [Archive] - VBForums [Archive] Showing a web page inside a literal control. ASP.NET. ... plugins/ modules to extend its functionality to met our business needs. ...
Extending "Panel", design-time display - ASP.NET Forums One shows the panel being used in ASP.NET markup, and the other .... Add( _collapseButton); _closeSpacer = new LiteralControl(" "); ...
Denis Bauer's Weblog - Software|ASP.NET Text; }. So, if you want to use literal controls with the DynamicControlsPlaceholder make sure that you use Literal instead of LiteralControl. ASP. ...




Search This Site:










only one general master sheet for all input screens

sql server doesn't permit remote access

webcontrol : event handler scope?

new server control - compiling question

absolute positioning

matt fleitz, about your software download

want make a control that can nest other controls

enable design time support for custom control in repeater

cnfiguring a domain name.

no add/remove button visible in design time collection

does someone know about a free hosting website

specifying a version number using csc

stringconverter on property always has context = null

hmc deployment

advanced web user controls resources

custom server control subclassed from panel not working correctly at design time

property editor control?

newbie question on custom control's

mass event processing suggestion

webhost supporting crystal reports

control gallery control

my containercontrol reformats the inner html....how can i stop it..

applying a mask to a password textbox control

a control that wont do squat!

property

articles on custom gridview fields

retaining property values in a user control

use ascx as server control?

web hosting for .net 1.1 and mssql server

finding a hosting package

  Privacy | Contact Us
All Times Are GMT