|
-
Jul 20th, 2004, 05:21 AM
#1
Making web control values persist [Resolved]
I just made the world's simplest Web Control.
VB Code:
Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
Output.Write("<b><u>" & _writewhat & "</u></b>")
End Sub
Public Property WriteWhat() As String
Get
Return _writewhat
End Get
Set(ByVal Value As String)
_writewhat = Value
End Set
End Property
See?
But I have no idea how I can make the values of these persist on postbacks.
Either there's some code I have to write, or I'm overlooking something simple.
So, how?
Last edited by mendhak; Jul 20th, 2004 at 07:20 AM.
-
Jul 20th, 2004, 06:52 AM
#2
I wonder how many charact
VB Code:
Private _writewhat As String = "default if not assigned"
Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
Output.Write("<b><u>" & [b]Me.WriteWhat[/b] & "</u></b>")
End Sub
Public Property WriteWhat() As String
Get
[b]If Me.ViewState("writewhat") Is Nothing Then[/b]
Return _writewhat
[b]Else
Return Me.ViewState("writewhat")
End If[/b]
End Get
Set(ByVal Value As String)
_writewhat = Value
[b]Me.ViewState.Add("writewhat",Value)[/b]
End Set
End Property
Last edited by nemaroller; Jul 20th, 2004 at 06:56 AM.
-
Jul 20th, 2004, 06:58 AM
#3
OK... I've understood that, thanks.
One more question, though:
You're doing a check like this:
VB Code:
If Me.ViewState("writewhat") Is Nothing Then
What exactly is this doing?
Is it not possible to just do a:
VB Code:
Public Property WriteWhat() As String
Get
Return CType(ViewState("WriteWhat"), String)
End Get
Set(ByVal Value As String)
ViewState("WriteWhat") = Value
End Set
End Property
?
-
Jul 20th, 2004, 07:19 AM
#4
No, wait, I did understand that line, my question is simply, can I do it the second way I just posted?
No... ok, never mind. I understood.
-
Jul 20th, 2004, 07:24 AM
#5
I wonder how many charact
Yea, you could do that.... doesn't matter...
I only wonder how expensive a Ctype operation is... so even though it looks cleaner, you should at least try invoking Ctype only after you have checked to see there is a reason to...
VB Code:
Public Property WriteWhat() As String
Get
If Me.ViewState("writewhat") Is Nothing Then
Return _writewhat
Else
Return Ctype(Me.ViewState("writewhat"),String)
End If
End Get
-
Jul 20th, 2004, 07:37 AM
#6
For that matter, ViewState seems to be pretty expensive too. So why not go for the whole shebang
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|