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
How can you handle unmanaged code exceptions in asp.net?
Why we use dbms for projects? Why don’t we save any application data in separate files instead of dbms?
Explain cashing in asp.net.
How can I create master page in asp net?
What symbol would you use to denote, the start of a code block in aspx views?
What is the difference between page.registerclientscriptblock and page.registerstartupscript?
How can we provide the WebParts control functionality to a server control?
What is the difference between sealed vs static class?
Explain managed code an un-managed code.
what are configuration files?
When Cookies are expired in ASP.NET?
Can we have multiple master pages in asp net?
Where is cookie used in asp.net?
What is asp.net web pages?
What is data grid view in asp.net?