View State allows you to retain page property values, such as string and numeric types, between postbacks. You may also store class objects in View State, but you must first add the Serializable attribute. If you do not add the Serializable attribute, you will receive this error when trying to add the object to View State:
Type 'SuchAndSuch.ThisAndThat' in Assembly 'SuchAndSuch, Version 1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
Here is an example of adding Serializable to a class:
<Serializable()>_
Public Class aMenu
Public MenuName As String
Public MenuId as Integer
Public Url as String
Public Sub New(ByVal menuName as String, ByVal menuId as Integer, ByVal url as String)
MenuName = menuName
MenuId = menuId
Url = url
End Sub
End Class
The aMenu class can now be added to View State:
Dim myMenu as New aMenu("Home",1,"/default.aspx")
ViewState("myMenu") = myMenu
To use the aMenu object:
If ViewState("myMenu") IsNot Nothing then
Dim myMenu as aMenu
myMenu = DirectCast(ViewState("myMenu"),aMenu)
End If
May your dreams be in ASP.NET!
Nannette Thacker
Ash explains the concept of Filtering Parameters in a Stored Procedure in this blog post.
This method is safer and more beneficial than dynamically creating and passing a sql query from the code layer and using sp_executesql, as it helps to avoid sql injection attacks.
However, the author explains there is a pitfall because you may sacrifice index optimization.
Check it out!
May your dreams be in ASP.NET and your code free from sql injections!
Nannette Thacker
Nathan Barry posted a new article on How To Use Icons To Support Content In Web Design.
Besides his design insights, he also provides images that depict actual live website examples and links to those sites.
His tips include How to Use Icons, Purpose and Placement, Icon Styles, and numerous examples.
Check it out!
May your dreams be in ASP.NET!
Nannette