1

I am using ASP.NET 3.5 with C# 2008.

I have a master page in which I have a grid view that have ItemCommand event. This master page has two child pages Page1.aspx and Page2.aspx.

Now, Page1.aspx has two division let us say div1 and div2.

By default div1 is visible and div2 remains hidden.

Now, the requirement is when I redirect to Page1.aspx from Page2.aspx, I want div1 visible. While, when I click any button from MasterPage's gridview, the ItemCommand event will be fired and that also will redirect me to Page1.aspx but at that time I need to show only div2 and want to make div1 hidden.

I can pass query string on ItemCommand event while redirecting to Page1.aspx using Response.Redirect("Page1.aspx?DisplayDivTwo=true"), but I don't want to follow such approach. Any other solution? I tried to set property before redirection but it is not working.

Dev
  • 6,570
  • 10
  • 66
  • 112

3 Answers3

4

Apart from Session and Querystring you can also use the Server.Transfer feature. You can then store the data in the Request.Items property of your page. They will be there on the page you're transferring to.

Alternatively you can use the Server.Transfer feature in combination with the PreviousPage directive in your aspx page.

MSDN has a pretty long article on all the options avialable to you. See:

And of course you can use a Single Page Application javascript framework to build the concept of pages in the client side, but actually only server one page from the server. You can then handle all the data going back and forth through json services.

Community
  • 1
  • 1
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Thanks for your answer and +1 for the detailed information. But if I use Server.Transfer then the URL will remain the same i.e. of previous page. So that it can create confusion to user that the name and tab visible to him is different from showing in URL. FYI, in my web application there are limited number of users and are technical persons. So I need to take care about the URL also displayed to which page they are. – Dev Jul 12 '13 at 05:43
  • Why would a technical person be concerned with the page url :). They should understand that the url doesn't matter. That aside, if you need to update the URL you'll need to use cookies, session or url parameters. Or you'll need to update something in your backend/database which reflects the choice of the user. Be really careful with these techniques and tech savvy users, they usually work with multiple tabs which can cause all kinds of issues when you don't do this right. – jessehouwing Jul 12 '13 at 08:43
3

You can use the following approach

1.Using Query String (Which is already implemented by you)

2.Using Session Variables

You are using asp.net better to use multi-view instead of Divs

Randhi Rupesh
  • 14,650
  • 9
  • 27
  • 46
1

So you want to pass data to another page without using query strings?

you can use session state

Session["DisplayDivTwo"]=="true"

and in your page1 page load

if(Session["DisplayDivTwo"]!=null)
string display= (string)Session["DisplayDivTwo"];
TheProvost
  • 1,832
  • 2
  • 16
  • 41