Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

8. Why do you want to work here?

1853


What is the difference between page.registerclientscriptblock and page.registerstartupscript?

799


Explain the different types of directives in .net?

877


What is session management in web application?

966


What are the new web part controls in asp.net 2.0 ?

967


Explain how do you validate the controls in an asp .net page?

862


What is manifest in .net framework?

974


Explain the difference between or and orelse?

924


What are the uses of list view control in Asp.net?

996


How use Xml data in ASP.net?

935


What is asp.net and how it works?

945


What is difference between viewstate and session state in javascript?

1050


Can we use a static function with a non-static variable?

925


what is loosely coupled solution? How it can be used?

958


We are using Jscriopt validations and at clint site javascript is not running that time validation would work? if yes then how it would behave?

1847