Originariamente inviato da pietro09
interessante
ma solo per i più bravi
. Io mi sono accontentato di modificare la proprietà readonly del textbox: funzionicchia
Guarda che è più facile di quello che si pensa. Io ho il difetto che non commento niente ma questo è un textbox riscritto che fa quello che chiede l'amico Maurizio.
codice:
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.SessionState
Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Configuration
Imports System.Collections.Specialized
Imports System.ComponentModel
Imports System.Security.Permissions
Public Class Text_Box : Inherits TextBox
Private lit1 As Literal
Private Testo1 As TextBox
Public Sub New()
MyBase.New()
End Sub
Public Property Abilitato() As Boolean
Get
Dim r As Object = ViewState("Abilitato")
If IsNothing(r) Then
r = True
Else
Return CBool(r)
End If
Return CBool(r)
End Get
Set(ByVal Value As Boolean)
ViewState("Abilitato") = Value
End Set
End Property
Public Property Opcode() As Long
Get
Return ViewState("Opcode")
End Get
Set(ByVal Value As Long)
ViewState("Opcode") = Value
End Set
End Property
Public Property Def() As String
Get
Return ViewState("Def")
End Get
Set(ByVal Value As String)
ViewState("Def") = Value
End Set
End Property
Protected Overrides Sub CreateChildControls()
If Not TextMode = TextBoxMode.MultiLine Then
lit1 = New Literal
lit1.Text = Text
If Opcode = 2 Then
If Def <> "" Then
Text = Def
Else
Text = ""
End If
End If
Else
If Opcode = 2 Then
Text = ""
Else
Text = Replace(Text, """, "''")
End If
TextMode = TextBoxMode.MultiLine
Font.Name = "Verdana"
Columns = Columns
Rows = Rows
If Opcode = 0 Then
BorderStyle = Me.BorderStyle = WebControls.BorderStyle.None
BackColor = Color.Transparent
Me.ReadOnly = True
End If
End If
If Not Abilitato Then
Enabled = False
End If
End Sub
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
If Opcode = 0 Then
If Not TextMode = TextBoxMode.MultiLine Then
lit1.RenderControl(writer)
Else
If Abilitato Then
If Text <> "" Then
If Len(Text) > Me.Columns Then
MyBase.Render(writer)
Else
lit1 = New Literal
lit1.Text = Text
lit1.RenderControl(writer)
End If
End If
Else
lit1.RenderControl(writer)
End If
End If
Else
If Abilitato Then
MyBase.Render(writer)
Else
lit1.RenderControl(writer)
End If
End If
End Sub
End Class
Le property sono:
Abilitato: Rende in sola lettura(Read only)
Opcode: Se=0 Riorna un literal con il valore
Se=1 ritorna un textbox normale
Se=2 ritorna un textbox con il testo impostato nella property "Def".
Per tutto il resto è un textbox normale.
Io ho messo il controllo, poi però va compilato in una dll per utilizzarlo.
Chiaramente il textbox è il più semplice dei controlli presenti normalmente in una pagina web, dai listbox in su la situazione si complica un pochettino.
P.S.
Questo controllo l'ho scritto con textpad (non c'era ancora vs.net) quando c'era ancora la beta uno del primo framework e, la prima volta l'ho compilato chiaramente con il compilatore a riga di comando....
Ciao
Legnetto