can we transfer data from one page to another page using
viewstate if so how?if not y?
Answer Posted / william niver
Yes, you can get the PreviousPage ViewSate.
I have created two pages (Default.aspx and LandingPage.aspx)
Default.aspx has a LinkButton with a PostBackUrl pointing
to LandingPage.aspx.
Code Behind for Default.aspx:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Me.Load
ViewState("MyValue") = "I am a test value"
End Sub
Public Function GetViewState() As System.Web.UI.StateBag
Return ViewState
End Function
End Class
Code Behind for LandingPage.aspx:
Partial Class LandingPage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Me.Load
If PreviousPageViewState IsNot Nothing Then
If PreviousPageViewState("MyValue") IsNot
Nothing Then
'Value is retrieved from the PreviousPage
ViewState
MyBase.Controls.Add(New LiteralControl
(PreviousPageViewState("MyValue")))
End If
End If
End Sub
Private ReadOnly Property PreviousPageViewState() As
StateBag
Get
Dim ReturnValue As System.Web.UI.StateBag =
Nothing
If PreviousPage IsNot Nothing Then
Dim MyTypeObj As Object = DirectCast
(PreviousPage, Object)
For Each MethodObj As Reflection.MethodInfo
In PreviousPage.GetType.GetMethods()
If MethodObj.Name = "GetViewState" Then
ReturnValue = MethodObj.Invoke
(MyTypeObj, Nothing)
Exit For
End If
Next
End If
Return ReturnValue
End Get
End Property
End Class
| Is This Answer Correct ? | 6 Yes | 2 No |
Post New Answer View All Answers
What are the cookies types in asp.net?
where can i gather the materials for MCP certification
What are the main differences between asp and asp.net?
What events will occur when a page is loaded?
Explain repository pattern in asp.net mvc? : asp.net mvc
Explain parts of assembly?
Which .NET framework supports Web API?
What is the difference between “Web.config” and “Machine.Config”?
What is http only cookie?
What is difference between viewstate and session state in javascript?
What does occur first in ASP.Net, Authentication or Authorization?
What is the recommended approach for asp.net mvc to globally intercept exceptions? What other functionality can be implemented with the approach? : Asp.Net MVC
What is a session government?
What is the page life cycle in asp.net?
Can we add code files of different languages in app_code folder?