0

I m working with hidden field

I want to display the first page data in second page using hiddenfield

first.aspx

<body>
    <form id="form1" runat="server">
      Name:<asp:TextBox ID="txtname" runat="server"></asp:TextBox><br />
      Address:<asp:TextBox ID="txtaddress" runat="server"></asp:TextBox><br />
        <asp:Button ID="Button1" runat="server" Text="Next" OnClick="Button1_Click" style="height: 26px" />
        <asp:HiddenField ID="hdnname" runat="server" />
        <asp:HiddenField ID="hdaddress" runat="server" />
    </form>
</body>

first.aspx.cs

    public partial class DemoHidden : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            hdnname.Value = txtname.Text;
            hdaddress.Value = txtaddress.Text;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }
    }

second.aspx

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

        nameget:<asp:Label ID="lblname" runat="server" Text="Label"></asp:Label><br />
        addressget:<asp:Label ID="lbladdress" runat="server" Text="Label"></asp:Label>

    </form>
</body>

second.aspx.cs

    public partial class Second : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //lblname.Text=txtname     //here I want to display the name and addresss
        }
    }

how to display the name and address when user fill up the first webform and display data in second webform page using hiddenfield?

help?

Raju
  • 75
  • 6
  • you can pass data between pages via `PostParameter`, `SessionState` or `QueryString` but not by using `HiddenFields` / `ViewState` – fubo May 26 '20 at 09:04
  • pass the data using query string from the first page to the second page and assign in a hidden field of the second page – SANDEEP May 26 '20 at 09:04
  • @fubo hidden field is stores data on single page? – Raju May 26 '20 at 09:05
  • @Raju right, `HiddenField` is stored in `ViewState` - page scope. P1 `Session["name"] = txtname.Text;` and P2 `lblname.Text= Session["name"].ToStrign();` is what you want to do – fubo May 26 '20 at 09:05
  • @fubo thanks working data displapy using session – Raju May 26 '20 at 09:24
  • @SANDEEP I m using session on first page and using hiddenfield on second page then not display the data?? see image https://i.stack.imgur.com/J0AAx.png how to assign a session in second page? – Raju May 26 '20 at 09:25
  • @Raju Pass data with query string instead of the session.session is not recommended way to pass data between pages. refer this https://www.c-sharpcorner.com/UploadFile/ca2535/query-string-in-Asp-Net/ – SANDEEP May 26 '20 at 10:02

0 Answers0