Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi, i have this code and this code not working properly
code in one.aspx

<asp:HiddenField runat="server" ID="hfDistrict" Value='<%# Eval("District")%>' />
<asp:HiddenField runat="server" ID="hfDistCode" Value='<%# Eval("DistCode") %>' />
<asp:LinkButton runat="server" ID="btn_NoOfA"  PostBackUrl="~/AcData.aspx" Text='<%# Eval("NoOfCount") %>' />


Code in AcData.aspx


string k = ((HiddenField)PreviousPage.FindControl("hfDistrict")).Value;



also try this code

string DistrictN1 = Request.Form["hfDistrict"]


but i did not get value from previous page
actually we need to remove querystring from old code and not want to use session and we are try to use postbackurl to pass value from one.aspx to AcData.aspx.
what is the exact problem i was doing and what will be the solution. plz provide solution thanks and regrds

What I have tried:

code in one.aspx
<pre><asp:HiddenField runat="server" ID="hfDistrict" Value='<%# Eval("District")%>' />
<asp:HiddenField runat="server" ID="hfDistCode" Value='<%# Eval("DistCode") %>' />
<asp:LinkButton runat="server" ID="btn_NoOfA"  PostBackUrl="~/AcData.aspx" Text='<%# Eval("NoOfCount") %>' />


Code in AcData.aspx


string k = ((HiddenField)PreviousPage.FindControl("hfDistrict")).Value;



also try this code

string DistrictN1 = Request.Form["hfDistrict"]
Posted
Updated 5-Aug-19 6:20am
v2

You already posted this in the ASP.NET forum. Please do not repost.
 
Share this answer
 
Read the documentation for Postbackurl, it contains examples of how to read the form values

Button.PostBackUrl Property (System.Web.UI.WebControls) | Microsoft Docs[^]
 
Share this answer
 
Your code for accessing the control value in AcData.aspx page should be inside the Page_Load event:

C#
void Page_Load (object sender, System.EventArgs e)
{
   string k = ((HiddenField)PreviousPage.FindControl("hfDistrict")).Value;
}


Another option that you can try is to use Server.Transfer:

1. Remove PostBackUrl from LinkButton
2. Add <asp:LinkButton OnClick="LinkButton1_Click" ... />
3. In your code behind , you can do something like this:

C#
protected void LinkButton1_Click(object sender, EventArgs e)
{
    Server.Transfer("~/AcData.aspx");

}


You can then access the value in the destination page like this:

C#
void Page_Load (object sender, System.EventArgs e)
{
HiddenField hid = (HiddenField)Page.PreviousPage.FindControl("hfDistrict");

if(hid != null)
      string key = hid.Value;

}


For more information, read: Cross-Page Posting in ASP.NET Web Forms
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900