If you are checking against null, you don't need to convert anything,
simply:
if ViewState("Info Width") is nothing Then
...
end if
will work.
That's actually the right way to do it, check for null BEFORE trying to
convert anything, otherwise you'll get nullreferenceex ceptions.
Once you are sure it isn't null, use it's ToString() method. This is what it
looks like:
Public Function ToString(ByVal formatProvider As IFormatProvider ) As String
Dim text1 As String
If Me.IsEmpty Then
Return String.Empty
End If
If (Me.type = UnitType.Pixel) Then
text1 = CInt(Me.value). ToString(format Provider)
Else
text1 = CSng(Me.value). ToString(format Provider)
End If
Return (text1 & Unit.GetStringF romType(Me.type ))
End Function
--
http://www.openmymind.net/ http://www.codebetter.com/
"shapper" <md*****@gmail. comwrote in message
news:11******** **************@ f16g2000cwb.goo glegroups.com.. .
Hello,
In a custom control property I have the following:
If CStr(ViewState( "InfoWidth" )) Is Nothing Then ...
I am getting the error:
Conversion from type 'Unit' to type 'String' is not valid.
Can someone tell me how can I convert the InfoWidth (Type =
WebControls.Uni t) to a string?
Thanks,
Miguel