CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011
    Posts
    63

    using Response.Redirect() and posting at the same time

    I'm trying to figure out how to post data in my C# codebehind while redirecting to another page. When the user clicks on a button in page1.aspx, he should be taken to page2.aspx. The C# codebehind of page2.aspx should be able to access a variable (a primary key) which is determined based on which button in page1.aspx was clicked. So page1.aspx needs to post the primary key that corresponds to that button, and page2.aspx needs to retrieve that primary key.

    I'm not sure how to do this while redirecting from page1.aspx to page2.aspx using Response.Redirect(). I heard Server.Transfer() might be able to do it, but I'm at a loss there to in understanding how to use it.

    The buttons in page1.aspx are in a table, which is in an ASP.NET content (i.e. <asp:content...>), which is declared/defined (I'm not sure what the right term is here) in a master page. All the contents in the master page are contained in a form. I mention this only because I've tried setting the method attribute in this form to "POST" without any luck, and also because you probably need to know the structure of my page.

    So is there a way to redirect to another page from the C# codebehind while at the same time posting data to be retrieved by that other page?

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: using Response.Redirect() and posting at the same time

    Redirect tells the user's browser to go and get another page
    UserBrowser> Hi server, give me page1's response to button1 being clicked
    Server> Hi browser, request page2 from me
    UserBrowser> Hi server, give me page 2
    Server> Hi browser, here's some data: "this is page 2"

    Server.Transfer gives another page responsibility for talking back to the browser
    UserBrowser> Hi server, give me page1's response to button1 being clicked
    Server> Hi browser, here's some data: "this is page 2"


    See the difference?
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured