Click here to Skip to main content
14,268,557 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

You already posted this in the ASP.NET forum. Please do not repost.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

Read the documentation for Postbackurl, it contains examples of how to read the form values

Button.PostBackUrl Property (System.Web.UI.WebControls) | Microsoft Docs[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Your code for accessing the control value in AcData.aspx page should be inside the Page_Load event:

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:

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

}


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

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
   

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




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