简体   繁体   中英

how to use session in transferring id from one aspx page to another aspx page

I have two aspx pages. The first one contains the gridview list of all the vessels and the other one consists the application form for permit. Once i select a row in the gridview list, a button for the permit application will be visible, this button once clicked, redirects to the second page which is the application form for permit. The problem is i have to get the id of the vessel from the selected row on the gridview list (first aspx page) and transfer it to the second aspx page. The id should be inserted in the permit application table together with the other data in the permit application form.

It sounds like this is your situation, roughly speaking: you have aspx pages A and B . Your user inputs something on A that is needed by B to render something else. To me the fact that you are rendering a table on B is irrelevant; if you could simply echo the value inputted from A onto B you would know what to do from there. So I am going to ignore the data table stuff.

You could use a session variable to transmit this value from A to B , but you probably shouldn't. There are a few good reasons not to do so; for starters, session variables are persisted in memory and therefore need to be managed.

If you insisted on using session variables, you would handle the event of, say, clicking submit on A by storing the text box's value into a session variable of your choice:

    Public Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Session("my_session_variable_name") = myTextBox.Text

    End Sub

And then in B , in the appropriate lifecycle event (say, on load) you would read the session variable and produce the table or whatever you are trying to accomplish:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Session("my_session_variable_name") <> "" Then
            id = Session("my_session_variable_name")
        End If

But I would highly discourage you from doing it this way. Instead, try to make your B page take in either a query string parameter or a POST ed body member, and read it using Request.QueryString[] or Request.Form[] .

You should use CommandName and CommandArgument attributes of the Button.

<asp:Button runat="server" ID="btn" CommandName="Permit" CommandArgument="6" />

But CommandArgument must be bind OnRowDataBound event of the gridview. So when you click you will check command name and get command argument value and pass it to permit form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM