ASP.NET
  Home arrow ASP.NET arrow Page 3 - ASP.NET Custom Server Controls: Combining ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

ASP.NET Custom Server Controls: Combining ImageHoverButton and RoundCorneredButton
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2005-10-31

    Table of Contents:
  • ASP.NET Custom Server Controls: Combining ImageHoverButton and RoundCorneredButton
  • Exposing properties for every side (including corners) of the button
  • Starting with the usual TABLE
  • Creating the header
  • Creating the body (content)
  • Closing the body (content) and creating the footer
  • How did I handle the post backs?
  • How is it different from my previous controls?

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    ASP.NET Custom Server Controls: Combining ImageHoverButton and RoundCorneredButton - Starting with the usual TABLE


    (Page 3 of 8 )

    The default “Render” method (when not overridden by us) usually calls “RenderBeginTag” before calling any other methods.  Let us examine the “RenderBeginTag” method in my control step by step:

    MyBase.AddAttributesToRender(writer)
           
    'registering JavaScripts
            If Not Page.IsStartupScriptRegistered(Me.ClientID &
    "_MouseOver")
    Then
                Page.RegisterStartupScript(Me.ClientID &
    "_MouseOver", getJS4MouseOver(Me.ClientID & "_MouseOver"))
           
    End If
            If Not Page.IsStartupScriptRegistered(Me.ClientID &
    "_MouseOut")
    Then
                Page.RegisterStartupScript(Me.ClientID & "_MouseOut",
    getJS4MouseOut(Me.ClientID & "_MouseOut"))
            End If

    Within the above method, I am trying to call the “MyBase.AddAttributesToRender(Writer)” statement to add any design-time attributes to my control.  This is a must when we use the control with the Visual Studio.NET designer.  You can also override with any other attributes you want (as shown in my previous articles of the same series).  The next two “if” structures will register two “hover” JavaScripts for the control.  Further proceeding, we have the following:

            'opening table
            writer.AddStyleAttribute("text-Align", "center")
            writer.AddStyleAttribute("vertical-Align", "middle")
            writer.AddStyleAttribute("cursor", "hand")
            writer.AddAttribute(HtmlTextWriterAttribute.Name,
    Me.UniqueID)
            writer.AddAttribute(HtmlTextWriterAttribute.Border,
    "0px")
            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,
    "0px")
            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing,
    "0px")
            writer.AddAttribute("onMouseOver", Me.ClientID &
    "_MouseOver();")
            writer.AddAttribute("onMouseOut", Me.ClientID &
    "_MouseOut();")
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
    Page.GetPostBackEventReference(Me, String.Empty))
            writer.RenderBeginTag(HtmlTextWriterTag.Table)

    From all the above statements, the conclusion would be something like: I am trying to render a “<TABLE>” tag with some attributes. I am also emitting “javascript” events at this stage itself, which means that the “hover” event applies to the whole table!  Another of the most important statements to concentrate on from above is this: 

    writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
    Page.GetPostBackEventReference(Me, String.Empty))

    That is the main trick I played to convert the “table” to “button.”  Once the above statement is executed, it now supports a post back when clicked!

    Starting simply with “<TABLE>” is not enough. We need to frame a 3x3 set of cells within the table.  I call the first row of cells header, second row of cells body (or content) and third row footer for a better understanding.

    In our next section, we shall see how to implement the header.

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Another ASP.NET control...enjoy and give me the feedback
     

    ASP.NET ARTICLES

    - More Advanced ASP.NET 3.5 Functions and Subr...
    - ASP.NET 3.5 Functions and Subroutines
    - Coding an IQ Test with Conditionally Driven ...
    - Developing Conditionally Driven Event Handle...
    - ASP.NET 3.5 Debugging Using Visual Web Devel...
    - Understanding Event Handlers in ASP.NET 3.5
    - Building a Web Form in ASP.NET and PHP: a Co...
    - Inserting Data into a Microsoft SQL 2008 Dat...
    - Creating an ASP.NET Dynamic Web Page Using M...
    - Retrieving Data from Microsoft SQL Server 20...
    - Building ASP.NET Web Forms to Use a MySQL Da...
    - Creating an ASP.NET Database using MS SQL 20...
    - Building an ASP.NET Website Using Include Ta...
    - Create ASP.NET Web Forms to Use a Microsoft ...
    - Editing Web Design Layout in Visual Web Deve...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek