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 is & in a url?
Define session in asp.net.
What are type/key pairs in client script registration? Can there be 2 scripts with the same type/key pair name?
Will the asp.net validators run in server side or client side?
What is a master page and what does it do?
Explain what is an assembly?
Hello, Using Visual Studio 2005 (VB) I am working to create a Web Site implementing the following: Within a gridView I have placed a dropdownlist control with a DataSourceID="SDSLkupList". SDSLkupList is a sqlDataSource used to store a lookup list for dropdownlist translation from ID to text. SDSLkupList contains the translation text and other fields related to the dropdown selection ID. (Thought it would be efficient to get everything at the same time.) I would like to provide the user the ability to select from the dropdownlist and, based on the selection, use labels to list related columns stored on the SDSLkupList in separate gridView columns. I have read that SqlDataSources are not meant to be used for individual controls. Since SDSLkupList contains all related information, is there a way to do a find using the dropdownlist selectedValue? (I was not able to discover one.) Otherwise, what should I use? It would need to set the labels on the gridView DataRowBound event as well as the SelectedIndexChanged events. Has anyone done this? Any help would be appreciated. Thanks in Advance. Neal
What are the properties of the eventargs argument when capturing keyboard events?
What is the difference between table and query?
What are the file extensions for razor views?
Can I tap into other windows livetm services?
In order to bind the data from a data source to the Repeater control what property is set and what method must you call in your code,?
What is asp net objects?
What are the main advantages of using asp.net?
Define the types of configuration files.