Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
ASP.NET 1.0/1.1
Web Controls e ViewState
giovedì 26 aprile 2007 - 21.45
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
volperubbia
Profilo
| Senior Member
375
messaggi | Data Invio:
gio 26 apr 2007 - 21:45
Ciao a tutti,
sto realizzando un controllo web, partendo da zero dalla classe System.Web.UI.WebControls.WebControl, è una semplice textbox cui vorrei far mantenere il valore nel ViewState.
Quando il controllo è visibile, tutto ok.
Quando il controllo invece passa da visibile a non visibile e poi nuovamente a visibile, lo parde.
Ad esempio, in una pagina aspx potrei simulare una tapstrip, e far vedere o meno la mia textbox.
Qualche idea?
Davide
Ecco il codice ...
Private _txtValue As String = Nothing
<Bindable(True), Category("Data"), DefaultValue("")> Property [Text]() As String
Get
If (_txtValue Is Nothing) Then _txtValue = ViewState("Text")
Return _txtValue
End Get
Set(ByVal Value As String)
ViewState("Text") = Value
_txtValue = Value
End Set
End Property
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
RenderInput(writer, Text, TextMode, InputClass, String.Empty)
End Sub
Protected Sub RenderInput(ByRef writer As System.Web.UI.HtmlTextWriter, _
ByVal strValue As String, _
ByVal TextMode As TextMode, _
Optional ByVal strInputClass As String = Nothing, _
Optional ByVal strReadOnlyClass As String = Nothing)
Dim blnReadOnly As Boolean ' = ... ... ...
blnReadOnly = False
writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID)
writer.AddAttribute(HtmlTextWriterAttribute.Id, UniqueID)
If (blnReadOnly) Then
writer.AddAttribute(HtmlTextWriterAttribute.Style, "BACKGROUND-COLOR: TRANSPARENT; BORDER-STYLE: NONE")
writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "TRUE")
If (strReadOnlyClass Is Nothing OrElse strReadOnlyClass.Equals(String.Empty)) Then
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%")
Else
writer.AddAttribute(HtmlTextWriterAttribute.Class, strReadOnlyClass)
End If
Else
If Not (strInputClass Is Nothing OrElse strInputClass.Equals(String.Empty)) Then writer.AddAttribute(HtmlTextWriterAttribute.Class, strInputClass)
End If
Select Case TextMode
Case DMUtility.CostantiWebControls.TextMode.SingleLine
writer.AddAttribute(HtmlTextWriterAttribute.Type, "TEXT")
writer.AddAttribute(HtmlTextWriterAttribute.Value, strValue)
writer.RenderBeginTag(HtmlTextWriterTag.Input)
Case DMUtility.CostantiWebControls.TextMode.MultiLine
writer.AddAttribute(HtmlTextWriterAttribute.Type, "MULTILINE")
writer.RenderBeginTag(HtmlTextWriterTag.Textarea)
writer.Write(strValue)
Case DMUtility.CostantiWebControls.TextMode.Password
writer.AddAttribute(HtmlTextWriterAttribute.Type, "PASSWORD")
writer.AddAttribute(HtmlTextWriterAttribute.Value, strValue)
writer.RenderBeginTag(HtmlTextWriterTag.Input)
End Select
writer.RenderEndTag()
End Sub
Protected Overrides Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean
Dim presentValue As String = Text
Dim postedValue As String = postCollection(postDataKey)
If (presentValue Is Nothing) OrElse (Not presentValue.Equals(postedValue)) Then
Text = postedValue
Return True
Else
Return False
End If
End Function
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !