Website Design United States, Website Design California, Website Designing United States, Website Designing California

Keeping Form Data - ASP.NET

This is a simple way of getting information from a post (form) and writing it to a new form. This is useful if the form is posted from another page but may be needed again throughout the rest of the use of the current page.

Request.Form.Keys.Item(Integer) returns a Key which is the name used for the element in the form.
Request.Form.Item(Key) returns the value of the Key (element) supplied.

In this case the hidden fields are put into a label (lblHiddenFields) which is contained within a form. If you wanted to make this a form simply add the tag to the beginning and tag to the end.

MakeHiddenField returns a string similar to the following:
<input type="hidden" name="someName" value="someValue" />

Dim intElement As Integer
Dim strKey As String
' Cycle through each element in the form
For intElement = 0 To Request.Form.Count - 1
strKey = Request.Form.Keys.Item(intElement)
' Ignore values with __ i.e. __VIEWSTATE since they are
' automatically added by ASP.NET
If Left(strKey, 2) <> "__" Then
lblHiddenFields.Text &= MakeHiddenField(strKey, _
Request.Form.Item(intElement)) & vbCrLf
End If

' Returns the html equivalent of a hidden field
Public Function MakeHiddenField( _
ByVal strName As String, _
ByVal strValue As String) As String
Return "<input type=""hidden"" name=""" & strName & """ value=""" & _
strValue & """ />"
End Function

42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Tel: 91-011-40502005, 9810067295



© 2008-2009