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?

Answers were Sorted based on User's Feedback



can we transfer data from one page to another page using viewstate if so how?if not y?..

Answer / guest

Yes we can transfer viewstate of page to another page.
Here is the code:
Create two pages one.aspx & two.aspx
in one.aspx page
protected void Page_Load(object sender, EventArgs e)
{
ViewState["page1"] = "page1 viewstate";
Server.Transfer("two.aspx");
}

public StateBag ReturnViewState()
{
return ViewState;
}
As you can see, I have set a ViewState variable in Page Load and transfer the user to two.aspx page using the Server.transfer() method. This page also contains a method ReturnViewState() which actually returns the ViewState of this page to the calling function. The return type of the method is StateBag class.

StateBag class: This class is the primary storage mechanism for all HTML and Web server controls. It stores attribute/value pairs as strings associated with the control. It tracks changes to these attributes only after the OnInit method is executed for a page request, and saves the changes to the page’s or control’s viewstate.

IN two.aspx page
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
if (PreviourPageViewstate() != null)
{
Label1.Text =Convert.ToString(PreviourPageViewstate()["page1"]);
}
}
}

private StateBag PreviourPageViewstate()
{

StateBag returnValue = null;
if (PreviousPage != null)
{
object prePage = (object)PreviousPage;
MethodInfo objMethod = prePage.GetType().GetMethod("ReturnViewState");
return (StateBag)objMethod.Invoke(prePage, null);
}
return returnValue;
}
Whenever we use Server.transfer or Cross Page Posting, We can get the previous page object via PreviousPage property. Using Previous Page, we can find the controls of the previous page. For example, one can access Label control placed in ViewStateContainer Page in current Page.

Looking at the code, I have created a PreviousPageViewState property in this page, which returns the previous page’s ViewState. It first checks whether PreviousPage is null or not, if it’s not null, then it creates an object of the previous page.

Now using Reflection, we can invoke the method of the previous class. Using MethodInfo class, I have invoked the ReturnViewState() method of ViewStateContainer Page.

In Page_Load event, I am able to access the ViewState variable of ViewStateContainer Page. You can access all the viewstate variables set in ViewStateContainer Page.

Run the application & see the effect

Is This Answer Correct ?    0 Yes 1 No

can we transfer data from one page to another page using viewstate if so how?if not y?..

Answer / k

no we can not do it like how we use session.
u store ur value in any contol find that control value from
current page.

TextBox txBox = (TextBox)PreviousPage.FindControl
("txtPreviousTest");
string urTextBox=txBox.Text;

Is This Answer Correct ?    0 Yes 2 No

can we transfer data from one page to another page using viewstate if so how?if not y?..

Answer / kranthi

Yes it is possibel!!!!!!!!!!!!
in pag1.aspx
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["name"] = txtTest.Text;

Server.Transfer("Default2.aspx");

}

In page2,aspx load event

protected void Page_Load(object sender, EventArgs e)
{
Page Poster = this.PreviousPage;

TextBox txtNewTest = (TextBox)Poster.FindControl
("txtTest");

string sDisplay = txtNewTest.Text.ToString();

Response.Write(sDisplay);



}

Is This Answer Correct ?    0 Yes 2 No

can we transfer data from one page to another page using viewstate if so how?if not y?..

Answer / anish.p.r

no we cant transfer data from one page to another page
using viewstate.
becouse in viewstate we can store only page level
information

Is This Answer Correct ?    3 Yes 6 No

can we transfer data from one page to another page using viewstate if so how?if not y?..

Answer / shravankumar

i feel it's possible to pass values from one page to
another using view state

Just try this :

Hold the values in viewstate which you want to transfer to
another page , in the next page where you want to pass the
values ,

In page_load
Access the values hold in view state

Just try this once :

Is This Answer Correct ?    2 Yes 6 No

can we transfer data from one page to another page using viewstate if so how?if not y?..

Answer / kuldeep khaware

Yes. We can transfer data one page two an other page
through View state.
Server.Transfer("secondpage.aspx view=textbox");

View state is page specific; it contains information about
controls embedded on theparticular page. resolves this by
embedding a hidden input field

" KULDEEP KHAWARE "

Is This Answer Correct ?    3 Yes 13 No

can we transfer data from one page to another page using viewstate if so how?if not y?..

Answer / pankaj

yes.using view state we can pass value of one page to another

Is This Answer Correct ?    52 Yes 82 No

Post New Answer

More ASP.NET Interview Questions

How can you provide an alternating color scheme in a Repeater control?

1 Answers  


Can you dynamically assign a Master Page?

0 Answers   MCN Solutions,


How do you add a javascript function for a link button in a datagrid?

2 Answers   Microsoft,


What is the difference between pathparam and queryparam?

0 Answers  


Which methods validate all the controls on a page?

0 Answers  


What's the difference between viewstate and sessionstate?

0 Answers  


how can i deploy a asp.net webapplication.in a company so that all employees may access application on their different computers and share a single database. plz tell me the steps to do it..thanks.

1 Answers  


main difference between asp.net2.0,asp.net1.1,asp.net1.0

1 Answers   Northgate is,


To which side ( server ? client) does the user input data validation occur? Explain the reasons for it?

1 Answers   Siebel,


If i have a web page, and one web user control, where in web page contains a text box, and web user control have check box, if i place a web user control in the webpage, when i check the check box, the out put should show it is checked or not. How we can do this?

1 Answers   CGI,


Why Unload event of MasterPage Calls first in ASP.net ?

0 Answers   HCL,


What is autopostback true?

0 Answers  


Categories