Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Custom control absolute positioning

Posted on 2005-05-06
6
Medium Priority
?
182 Views
Last Modified: 2010-04-07
Hi,

I've build a couples of web controls and I was wondering how can we made those control behave like MS builtin controls with absolute positioning.

I think I should implement top and left properties in my controls and then render the server "style" tag, but I don't really know how to do that.

Here's the code of one of the simpliest control.

Option Explicit On
Option Strict On

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls


Public Class ctlStatus
    Inherits Control

    Dim _message As String
    Dim _icon As Integer
    Dim _pict As String
    Dim _col As String
    Dim _style As String

    Property Message() As String
        Get
            Return _message
        End Get
        Set(ByVal Value As String)
            _message = Value
        End Set
    End Property

     Property Icon() As Integer
        Get
            Return _icon
        End Get
        Set(ByVal Value As Integer)
            _icon = Value
            Select Case _icon
                Case 0
                    _pict = "./images/stats_nothing_big.png"
                    _col = "#cdcbbc"
                Case 1
                    _pict = "./images/stats_warning_big.png"
                    _col = "yellow"
                Case 2
                    _pict = "./images/stats_error_big.png"
                    _col = "red"
                Case 3
                    _pict = "./images/stats_critical_big.png"
                    _col = "red"
                Case 4
                    _pict = "./images/stats_info_big.png"
                    _col = "green"
                Case Else
                    _pict = "./images/stats_nothing_big.png"
                    _col = "#cdcbbc"
            End Select
        End Set
    End Property

    Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
        writer.Write(("<span id=""Label1"" style=""Z-INDEX: 101; LEFT: 124px; POSITION: absolute; TOP: 760px"">") & vbCr)

        writer.Write(("<DIV style=""Z-INDEX: 101; WIDTH: 100%; POSITION: relative;HEIGHT: 36px"" >"))
        writer.Write(("      <TABLE id=""Table3"" style=""BORDER-RIGHT: gray 1px solid; BORDER-TOP: gray 1px solid; Z-INDEX: 101; LEFT: 0px; BORDER-LEFT: gray 1px solid; WIDTH: 100%; BORDER-BOTTOM: gray 1px solid; POSITION: absolute; TOP: 6px"""))
        writer.Write(("            borderColor=""black"" height=""21"" cellSpacing=""0"" cellPadding=""0"" width=""100%"" bgColor=""" & Me._col & """"))
        writer.Write(("            border=""0"">"))
        writer.Write(("            <TR>"))
        writer.Write(("                  <TD style=""WIDTH: 5%; FONT-FAMILY: tahoma"" align=""left""><P align=""center""><FONT style=""FONT-SIZE: 9pt; FONT-FAMILY: tahoma"" face=""Times New Roman"" size=""3""></FONT>&nbsp;</P>"))
        writer.Write(("                  </TD>"))
        writer.Write(("                  <TD id=""status_msg"" style=""FONT-WEIGHT: bold; FONT-SIZE: 9pt; WIDTH: 95%; FONT-FAMILY: tahoma"" align=""left"">" & Me.Message & "</TD>"))
        writer.Write(("            </TR>"))
        writer.Write(("      </TABLE>"))
        writer.Write(("      <IMG id=""status_img"" style=""Z-INDEX: 102; LEFT: 0px; WIDTH: 51px; POSITION: absolute; TOP: 0px; HEIGHT: 31px"""))
        writer.Write(("            alt="""" src=""" & Me._pict & """></DIV>"))
        writer.Write(("</span>"))

    End Sub
End Class

Thanks
0
Comment
Question by:hqdev
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
ovalsquare earned 375 total points
ID: 13952156
First, you'd be better off removing the html from your code-behind, setting label properties etc to take care of your Message etc. - maintenance for this kind of setup is yucky. Then you'll also have design time ability to deal with your layout (although it's much better to avoid dealing with absolute positioning with html. It's better to control it using flowlayout).

I'm probably not answering your question, but have to sign off!

Ted
0
 

Author Comment

by:hqdev
ID: 13977116
I finally use a HTML grid layout and put the control in it.
0
 
LVL 5

Expert Comment

by:ovalsquare
ID: 13978481
Sounds good - a much better approach (although you'll find that if you go with FlowLayout, you'll be happier in the long run - but no biggy - the big thing was getting it out of your code-behind).

Ted
0
 
LVL 5

Expert Comment

by:ovalsquare
ID: 13999145
Uh, my response was what the asker ended up implementing so I believe I should receive the points.

Thanks,

Ted
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question