web 2.0

ASP.NET(vb.net) Session & Object Value

ASP.NET(vb.net) Session & Object Value - Session & Object Value : The learn and script how to use Session and Object variable.

ShotDev Focus:
- ASP.NET(vb.net) Session & Object Value

Example

AspNetSessionObject.aspx

  1. <%@ Import Namespace="System.Data"%>  
  2. <%@ Import Namespace="System.Data.OleDb"%>  
  3. <%@ Page Language="VB" %>  
  4. <script runat="server">  
  5. Sub Page_Load(sender As Object, e As EventArgs)  
  6.   
  7. '*** Create Object Session ***'  
  8. Dim objFSO, objStream As Object  
  9. objFSO = Server.CreateObject("Scripting.FileSystemObject")  
  10.   
  11. '*** Used Session ***'  
  12. Session("mySession") = objFSO  
  13.   
  14. objStream = Session("mySession").OpenTextFile(Server.MapPath("MyFiles/shotdev.txt"))  
  15.   
  16. Do Until objStream.AtEndOfStream  
  17. Me.lblText1.Text = Me.lblText1.Text & objStream.ReadLine & "<br>"  
  18. Loop  
  19. objStream.Close()  
  20. objStream = Nothing  
  21.   
  22. '*** New Control & Session ***'  
  23. Dim objConn As OleDbConnection  
  24. Dim objCmd As OleDbCommand  
  25. Dim strConnString As String  
  26. strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";"  
  27. objConn = New OleDbConnection(strConnString)  
  28. objConn.Open()  
  29. Dim strSQL As String  
  30. strSQL = "SELECT * FROM customer"  
  31. Dim dtReader As OleDbDataReader  
  32. objCmd = New OleDbCommand(strSQL, objConn)  
  33. dtReader = objCmd.ExecuteReader()  
  34.   
  35. '*** GridView Session ***'  
  36. Dim myGridView As New GridView  
  37. Session("myControl") = myGridView  
  38.   
  39. Dim myCtrl As GridView = CType(Session("myControl"), GridView)  
  40.   
  41. With myCtrl  
  42. .AutoGenerateColumns = True  
  43. .DataSource = dtReader  
  44. .DataBind()  
  45. End With  
  46.   
  47. '*** Load Control To Label ***'  
  48. Me.lblText2.Controls.Add(myCtrl)  
  49.   
  50. dtReader.Close()  
  51. dtReader = Nothing  
  52. objConn.Close()  
  53. objConn = Nothing  
  54.   
  55. End Sub  
  56. </script>  
  57. <html>  
  58. <head>  
  59. <title>ShotDev.Com Tutorial</title>  
  60. </head>  
  61. <body>  
  62. <form runat="server">  
  63. <asp:Label id="lblText1" runat="server"></asp:Label>  
  64. <hr />  
  65. <asp:Label id="lblText2" runat="server"></asp:Label>  
  66. </form>  
  67. </body>  
  68. </html>  

Screenshot

ASP.NET(vb.net) Session & Object Value
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.