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