Creating server control

Posted on 2011-05-12
Last Modified: 2012-08-30
Hi! is this the correct way of doing thing?

Creating a specific css class for a specific control, Is the correct implementation? or do you have any other suggestion...

Your comment is greatly appreciated.

Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

<Serializable()> _
Public Class SmartItems
    Inherits WebControl

    Private _CSSLocation As String = ""
    <Browsable(True)> _
    Public Property CSSLocation() As String
            Return _CSSLocation
        End Get
        Set(ByVal value As String)
            _CSSLocation = value
        End Set
    End Property

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

        'Creating a specific css class for a specific control, Is the
        'correct implementation?
        writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css")
        writer.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet")
        writer.AddAttribute(HtmlTextWriterAttribute.Href, _CSSLocation)

        writer.AddAttribute(HtmlTextWriterAttribute.Class, "MainContainer")
    End Sub
End Class

Open in new window

Question by:PagodNaUtak
    LVL 16

    Accepted Solution

    LVL 8

    Author Comment

    Nice article, but what I need to know is the way I render the CSS inside the control.

    Is this the correct approach? how do I implement the CSS is it inside the control or in the page?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now