locked
Creating a custom label control for repeat text RRS feed

  • Question

  • User-1780297765 posted
    Hello, I am trying to write a custom label control that will allow me to display the same, configurable, text MULTIPLE times on the same page. I am tired of doing things like this on pages: "Welcome <asp:label runat=server id='lblname_1'/> to the site. <asp:label runat=server id='lblname_2'/>, how would you like to check out what we have? It's now possible <asp:label runat=server id='lblname_3'/>." and then doing this in the codefile: lblname_1 = 'Josh' lblname_2 = 'Josh' lblname_3 = 'Josh' etc etc. I would prefer to be able to do something like this: "Welcome <cc:mycontol runat=server id='lblname_1'/> to the site. <cc:mycontol runat=server id='lblname_2'/>, how would you like to check out what we have? It's now possible <cc:mycontol l runat=server id='lblname_3'/>." and SOMEWHERE set the text property = 'Josh' so I only need to set it once. Does anyone have any ideas how to do this? Thanks, Josh
    Friday, August 8, 2008 9:53 AM

Answers

  • User-16411453 posted

     I use a ini file, But I'm going to upgrade it to an xml file called CompanyInfo.xml. You set the CompanyInfo, and just call the value you need when needed.

    In a server control, you make a property, and call the property name when needed. 

     

     

    Imports Microsoft.VisualBasic
    Imports System.Web
    Imports System.Security.Cryptography.DES
    Imports System.Security.Cryptography.TripleDES
    Imports System.Security.Cryptography.RC2
    Imports System.Security.Cryptography.Rijndael
    Imports System.Diagnostics
    Imports System.Security.Cryptography
    Imports System.Text
    Imports System.IO

    Public Class IniFile
    Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As System.Text.StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    Private Declare Ansi Function
    WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
    Private Declare Ansi Function
    GetPrivateProfileInt Lib "kernel32.dll" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
    Private Declare Ansi Function
    FlushPrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As Integer, ByVal lpKeyName As Integer, ByVal lpString As Integer, ByVal lpFileName As String) As Integer
    Dim
    strFilename As String
    Public Sub New
    (ByVal Filename As String)
    strFilename = Filename
    End Sub
    ReadOnly Property
    FileName() As String
    Get
    Return
    strFilename
    End Get
    End Property
    Private Function
    GetString(ByVal Section As String, ByVal Key As String, ByVal [Default] As String) As String

    ' Returns a string from your INI file
    Dim intCharCount As Integer
    Dim
    objResult As New System.Text.StringBuilder(256)
    intCharCount = GetPrivateProfileString(Section, Key, [Default], objResult, objResult.Capacity, strFilename)
    If intCharCount > 0 Then
    GetString = Left(objResult.ToString, intCharCount)
    Else
    GetString = Nothing
    End If
    Return
    GetString

    End Function
    Private Function
    GetInteger(ByVal Section As String, ByVal Key As String, ByVal [Default] As Integer) As Integer

    ' Returns an integer from your INI file
    Return GetPrivateProfileInt(Section, Key, [Default], strFilename)

    End Function
    Private Function
    GetBoolean(ByVal Section As String, ByVal Key As String, ByVal [Default] As Boolean) As Boolean

    ' Returns a boolean from your INI file
    Return (GetPrivateProfileInt(Section, Key, Convert.ToInt32([Default]), strFilename) = 1)

    End Function
    Private Sub
    WriteString(ByVal Section As String, ByVal Key As String, ByVal Value As String)

    ' Writes a string to your INI file
    WritePrivateProfileString(Section, Key, Value, strFilename)
    Flush()

    End Sub
    Private Sub
    WriteInteger(ByVal Section As String, ByVal Key As String, ByVal Value As Integer)

    ' Writes an integer to your INI file
    WriteString(Section, Key, CStr(Value))
    Flush()

    End Sub
    Private Sub
    WriteBoolean(ByVal Section As String, ByVal Key As String, ByVal Value As Boolean)

    ' Writes a boolean to your INI file
    WriteString(Section, Key, CStr(Convert.ToInt32(Value)))
    Flush()

    End Sub
    Private Sub
    Flush()

    ' Stores all the cached changes to your INI file
    FlushPrivateProfileString(0, 0, 0, strFilename)

    End Sub
    Public Shared Function
    GetCompanyInfo() As Array

    Dim Context As HttpContext = HttpContext.Current
    Dim CompanyInfo(17) As String
    Dim
    ThePath As String = Nothing
    ThePath = Context.Request.PhysicalApplicationPath()

    Try
    Dim
    objIniFile As New iCE5IniFile(ThePath & "CompanyInfo.ini")
    CompanyInfo(0) = objIniFile.GetString("CompanyInfo", "CompanyName", "(none)")
    CompanyInfo(1) = objIniFile.GetString("CompanyInfo", "Address1", "(none)")
    CompanyInfo(2) = objIniFile.GetString("CompanyInfo", "Address2", "(none)")
    CompanyInfo(3) = objIniFile.GetString("CompanyInfo", "City", "(none)")
    CompanyInfo(4) = objIniFile.GetString("CompanyInfo", "State", "(none)")
    CompanyInfo(5) = objIniFile.GetString("CompanyInfo", "ZipCode", "(none)")
    CompanyInfo(6) = objIniFile.GetString("CompanyInfo", "Email", "(none)")
    CompanyInfo(7) = objIniFile.GetString("CompanyInfo", "Phone1", "(none)")
    CompanyInfo(8) = objIniFile.GetString("CompanyInfo", "Fax", "(none)")
    CompanyInfo(9) = objIniFile.GetString("CompanyInfo", "WebSiteName", "(none)")
    CompanyInfo(10) = objIniFile.GetString("CompanyInfo", "SAddress1", "(none)")
    CompanyInfo(11) = objIniFile.GetString("CompanyInfo", "SAddress2", "(none)")
    CompanyInfo(12) = objIniFile.GetString("CompanyInfo", "SCity", "(none)")
    CompanyInfo(13) = objIniFile.GetString("CompanyInfo", "SState", "(none)")
    CompanyInfo(14) = objIniFile.GetString("CompanyInfo", "SZipCode", "(none)")
    CompanyInfo(15) = objIniFile.GetString("CompanyInfo", "CountryCode", "(none)")
    CompanyInfo(16) = objIniFile.GetString("CompanyInfo", "SCountryCode", "(none)")

    objIniFile = Nothing

    Catch
    ex As Exception

    End Try

    Return
    CompanyInfo

    End Function
    Public Sub
    WriteCompanyInfo(ByVal CompanyInfo As Array)

    Dim Context As HttpContext = HttpContext.Current
    Dim ThePath As String = Nothing
    ThePath = Context.Request.PhysicalApplicationPath()
    'Context.Response.Write("ThePath=" & ThePath)

    Try
    Dim
    objIniFile As New iCE5IniFile(ThePath & "CompanyInfo.ini")
    'CompanyInfo(0) = sCompanyName
    'CompanyInfo(1) = sAddress1
    'CompanyInfo(2) = sAddress2
    'CompanyInfo(3) = sCity
    'CompanyInfo(4) = sState
    'CompanyInfo(5) = sZipCode
    'CompanyInfo(6) = Email
    'CompanyInfo(7) = sPhone1
    'CompanyInfo(8) = sFax
    'CompanyInfo(9) = sWebsiteName

    'Write the Information

    objIniFile.WriteString("CompanyInfo", "CompanyName", CompanyInfo(0))
    objIniFile.WriteString("CompanyInfo", "Address1", CompanyInfo(1))
    objIniFile.WriteString("CompanyInfo", "Address2", CompanyInfo(2))
    objIniFile.WriteString("CompanyInfo", "City", CompanyInfo(3))
    objIniFile.WriteString("CompanyInfo", "State", CompanyInfo(4))
    objIniFile.WriteString("CompanyInfo", "ZipCode", CompanyInfo(5))
    objIniFile.WriteString("CompanyInfo", "Email", CompanyInfo(6))
    objIniFile.WriteString("CompanyInfo", "Phone1", CompanyInfo(7))
    objIniFile.WriteString("CompanyInfo", "Fax", CompanyInfo(8))
    objIniFile.WriteString("CompanyInfo", "WebsiteName", CompanyInfo(9))
    objIniFile.WriteString("CompanyInfo", "SAddress1", CompanyInfo(10))
    objIniFile.WriteString("CompanyInfo", "SAddress2", CompanyInfo(11))
    objIniFile.WriteString("CompanyInfo", "SCity", CompanyInfo(12))
    objIniFile.WriteString("CompanyInfo", "SState", CompanyInfo(13))
    objIniFile.WriteString("CompanyInfo", "SZipCode", CompanyInfo(14))
    objIniFile.WriteString("CompanyInfo", "CountryCode", CompanyInfo(15))
    objIniFile.WriteString("CompanyInfo", "SCountryCode", CompanyInfo(16))
    objIniFile = Nothing

    Catch
    ex As Exception

    End Try

    End Sub

      

     

     

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 8, 2008 6:41 PM