开发者

How do I transfer a value from one page to another in hidden parameters instead of a querystring?

开发者 https://www.devze.com 2023-02-14 02:09 出处:网络
What\'s wrong with this code? Source page : Default.aspx <form id=\"form1\" action =\"Default2.aspx\" method=\"post\" runat=\"server\">

What's wrong with this code?

Source page : Default.aspx

 <form id="form1" action ="Default2.aspx" method="post" runat="server">
            <table>
            <tr>
                <td>Merchant Id</td>
                <td><asp:TextBox ID="SRCSITEID" Text="T521" runat="server"></asp:TextBox></td>
            </tr>
               </table>
        <table>
            <tr>
                <td>
                    <asp:Button ID="Submit" runat="server" Text="Submit" /></td>
            </tr>
        </table>          
    </form>

Destination开发者_如何转开发 page : Default2.aspx

<form id="form1" runat="server">
    <div>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    </div>
    </form>

Default2.aspx.vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            TextBox1.Text = Request("SRCSITEID").ToString()
        Catch
        End Try
    End Sub


You could try

Page1

Session["someKey"] = ValueFromPage1;

and in Page2

var valueFromPage1 = Session["someKey"];


try

Request.Form("SRCSITEID")

because you use post method


Take a look at Cross Page Posting (MSDN Link)

It's like doing a postback only you post back to a completely different page.

Example Code:

If Not Page.PreviousPage Is Nothing Then
   Dim SourceTextBox As TextBox
   SourceTextBox = CType(PreviousPage.FindControl("SRCSITEID"), TextBox)
   If Not SourceTextBox Is Nothing Then
       TextBox1.Text = SourceTextBox.Text
   End If
End If
0

精彩评论

暂无评论...
验证码 换一张
取 消