Passing a variable to a page, but then I need to pass it right back to the calling page RRS feed

  • Question

  • User1104256871 posted

    Here is the issue.   I have a page that passes a variable like I have listed below adding an user to active assignments.  The sending page sends the ID through the URL.   In this case, the active record is 4 as it shows


        Layout = "~/_Layout.cshtml";
        var id = Request["uid"];
    var UserID = ""; var ActiveID ""; if(IsPost && Validation.IsValid()){ ActiveID = Request.Form["ActiveID"]; UserID = Request.Form["UserID"]; var db = Database.Open("SQL03"); var insertCommand = "INSERT into tblAssign (ActiveID, UserID) Values(@0, @1)"; db.Execute(insertCommand, ActiveID, UserID); Response.Redirect("~/Active/Active.cshtml"); } }

    What my clients wants is to change the redirect to the page that sent the us to add the user in the first place. It is a grid that shows all of the active users for project 4.   The redirect is where I am having a problem.  I want to pass back the ID that I got in the redirect, but I keep getting errors as the same value of UID is in both pages.  So where it shows this variable in the redirect


    I would like to go this page after I add the user


    Which in this case would be 4.  How would I store that value off and then pass it back.  Any assistance is appreciated...

    Monday, April 25, 2016 3:43 PM


All replies

  • User753101303 posted


    Mark X

    I keep getting errors as the same value of UID is in both pages.

    It's likely best to be more explicit about what happens.

    Seems it would be somerthing such as


    assuming your source page already uses Request["uid"]to filter the list. If you tried and it doesn't work post directly about the error you have. When something that should work doesn't work it is likely easier to see what is wrong than to explain again what you seems to know already without knowing if it will help or not to solve your current unknown issue.

    Another option is that yopu are confusing maybe a user id and a project id (in the code you shown uid doesn't seems to be used at all ?). Or maybe you keep this value to just pass it back to the other page?

    For now it just seems you are missing that can you use Request["uid"] to read the value and transmit it back to the other page by just constructing the correct url for your Response.Redirect method.

    Monday, April 25, 2016 4:03 PM
  • User1104256871 posted

    Sorry about not giving enough information, but your answer was spot on even with the lack of information.   I can now go back and forth between the pages and keep the same records showing.  It is going to save me about 3 steps in the processing.  Thank you for your assistance.

    Monday, April 25, 2016 4:51 PM
  • User1149660278 posted

    Take a look at this article, it might help you:


    Specifically I would take a look at "Session Varables", this might help in your Situation.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 30, 2016 6:48 PM
  • User379720387 posted

    Session variables are a solution, but they might disappear if your hosting provider decides to 'spool' down your server when there is no demand.

    Saturday, April 30, 2016 6:51 PM