views:

63

answers:

4

I have a page and clicked on the button there it will open a new page containing some text boxes, user fill all the text boxes and clicked the button now first page open again and the question is : How can I get the vales of text boxes on the current page using both server-side and client-side

There is a restrictions to use of : - Cross-paging - Cookies - Sessions - Query strings

A: 

If you are using the PostBackUrl property of the button on the submitting page, you can access the controls for the "previous page" from the action page by using the following:

Dim txtBox as TextBox
txtBox = CType(Page.PreviousPage.FindControl("MyTextBox"), TextBox)

Then you'll have access programmatically to all of the properties and data for that control.

Joel Etherton
There is restriction to use Cross-paging
Rick
He can't use any of `Cross-paging - Cookies - Sessions - Query strings`
Jim Schubert
A: 

Use the cache if you can't use the Session, Querystring, Cookies and Cross Page posting.

John Hpa
A: 

If it is simple/primitive data, then you can go for the ViewState. Or Cache is a better option. One more option is to have a Page level public variables, set the required values and redirect to the page for further processing.(This is not a good approach to follow)

Kay
A: 

Server-side approach:

An alternate approach is to use Server.Transfer method.

On the current page:

protected void Transfer_Click(object sender, EventArgs e)
{
  if (Page.IsValid)
  {
    Server.Transfer("destination.aspx");
  }
}

On the destination page:

protected void Page_Load(object sender, EventArgs e)
{
  if (PreviousPage != null)
  {
    TextBox textBox = PreviousPage.FindControl("Parameter")
                        as TextBox;

    if (textBox != null)
    {
      string parameter = textBox.Text;
      Parameter.Text = parameter;
    }

  }   
}

But Server.Transfer does come with disadvantages. The most serious is that the URL in the browser does not change. The browser still believes it has posted back and received content for the first web form, so history and book-marking suffer.

Client-side approach:

In real world I don't recommend to use this solution, this is only a workaround.

In two words: use window.name property on the client side. This property is available across page reloads it is a sort of session.

For more information see:

Hope, this helps.

Alex
@Alex what about client-side
Rick