Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi all,
I am developing a web application in which i need to store a some values in a hiddenfield and i need to access this values in other pages. I need to post huge data and so i prefer using HiddenField than Session or QueryString. I am using the following code.
 
Default1.aspx
 
 <asp:HiddenField ID="hdnEmailID" runat="server" />
 
Default1.aspx.cs
 
protected void LinkGroupSummary_Click(object sender, EventArgs e)
        {            
            hdnEmailID.Value = this.EmailList;
            Server.Transfer("Default2.aspx");
 
        }
 
Default2.aspx.cs
 

if (Page.PreviousPage != null)
                    {
                        HiddenField MyHiddenValue = (HiddenField)Page.PreviousPage.FindControl("hdnEmailID");
                        if (MyHiddenValue != null)
                        {
                            string email = MyHiddenValue.Value;
                        }
                    }

In the Default.aspx.cs page, i am getting MyHiddenField as null always.
 
Please help.
 
Thanks in advance,
Sruthi R
Posted 18-Jun-12 16:40pm
SruthiR1.3K
Edited 18-Jun-12 18:30pm
sravani.v15.7K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

How to: Pass Values Between ASP.NET Web Pages[^] should be the perfect link for you to go through. Have a look at how _VIEWSTATE_ automatically passes hidden fields when posting data.
  Permalink  
Comments
Amit Kmr Sinha at 18-Jun-12 23:56pm
   
Good reference. MSDN is the best. My +5.
Pankaj Nikam at 19-Jun-12 1:26am
   
+5 Awesome!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hello freinds,
//use this code
 
suppose i have 2 page. A.aspx and B.aspx
I have pass value of page a to page b using hidden field
//take hiddenfield on page, one button with hidden property and write one script
 
<script type="text/javascript">
        function load(id) {
            document.getElementById('<%=HiddenField1.ClientID%>').value = id;
            document.getElementById("<%= ButtonHide.ClientID %>").click();
        }
        </script>
 

 
<asp:HiddenField ID="HiddenField2" runat="server" />;
<asp:Button ID="ButtonHide" runat="server" Text="Button" style="display:none;"
                           formnovalidate="true"     onclick="ButtonHide_Click"/>
 
//in code file of page a
 protected void ButtonHide_Click(object sender, EventArgs e)
    {
        Response.Redirect("PriceDetail.aspx?id="+HiddenField1.Value+"");
    }
 
now in page b code file
 
int id = Convert.ToInt32(Request.Params["id"]);
and u get value of hiddenfield
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi,
 
make it a server control hiddenfield. Set the PostbackUrl property of the button to the next page and retrieve the information there.
 
For a good example on how to use the PostBackUrl property take a look at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.postbackurl.aspx.
 
Page 1:
<%@ page language="C#" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>Button.PostBackUrl Example</title>
</head>
<body>
  <form id="form1" runat="server">
 
    <h3>Button.PostBackUrl Example</h3>
 
    Enter a value to post:
    <asp:textbox id="TextBox1"
      runat="Server">
    </asp:textbox>
 
    <br /><br />
 
    <asp:button id="Button1"
      text="Post back to this page"
      runat="Server">
    </asp:button>
 
    <br /><br />
 
    <asp:button id="Button2"
      text="Post value to another page"
      postbackurl="Button.PostBackUrlPage2cs.aspx"
      runat="Server">
    </asp:button>
 
  </form>
</body>
</html>
 
Button.PostBackUrlPage2cs.aspx:
 
<%@ page language="C#" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  void Page_Load (object sender, System.EventArgs e)
  {
    string text;
 
    // Get the value of TextBox1 from the page that
    // posted to this page.
    text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
 
    // Check for an empty string.
    if (text != "")
      PostedLabel.Text = "The string posted from the previous page is "
                         + text + ".";
    else
      PostedLabel.Text = "An empty string was posted from the previous page.";
  }
 
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>Button.PostBackUrl Target Page Example</title>
</head>
<body>
  <form id="form1" runat="server">
 
    <h3>Button.PostBackUrl Target Page Example</h3>
 
    <br />
 
    <asp:label id="PostedLabel"
       runat="Server">
    </asp:label>
 
    </form>
</body>
</html>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 768
1 OriginalGriff 420
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 17 Feb 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100