如何从asp.net中的上一页到下一页获取隐藏字段值
问题描述:
大家好,
我正在开发一个Web应用程序,我需要在隐藏字段中存储一些值,我需要在其他页面中访问此值。我需要发布大量数据,所以我更喜欢使用HiddenField而不是Session或QueryString。我使用以下代码。
Default1.aspx
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
Default1.aspx.cs
protected void LinkGroupSummary_Click(object sender, EventArgs e)
{
hdnEmailID.Value = this.EmailList;
Server.Transfer("Default2.aspx");
}
Default2.aspx.cs
Default2.aspx.cs
if (Page.PreviousPage != null)
{
HiddenField MyHiddenValue = (HiddenField)Page.PreviousPage.FindControl("hdnEmailID");
if (MyHiddenValue != null)
{
string email = MyHiddenValue.Value;
}
}
在Default.aspx.cs页面中,我总是将MyHiddenField作为null。
请帮忙。
提前致谢,
Sruthi R
In the Default.aspx.cs page, i am getting MyHiddenField as null always.
Please help.
Thanks in advance,
Sruthi R
答
如何:在ASP之间传递值。 NET网页 [ ^ ]应该是你完成的完美链接。看看_VIEWSTATE_在发布数据时如何自动传递隐藏字段。
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.
点击这里
http://codingboys.blogspot.in/2012/11/how-to-get-previous-page-value-in -aspnet.html [ ^ ]
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