This shows the patient details page when <a href="" /> is clicked (anchor tag is inside repeater):
function showPatient(Pid) {
RedirectToPage("Patient_Registration.aspx","pid="+Pid);
return false;
}
<asp:Repeater ID="repeaterPatientList" runat="server" OnItemDataBound="repeaterPatientList_ItemDataBound" >
<ItemTemplate>
<a href="#" onclick="return showPatient('<%#Eval("PID") %>')"><%#Eval("Patient_Name")%></a>
</ItemTemplate>
</asp:Repeater>
I am getting pID as query string on patient details page. After getting pID on first page load the patient information is filled into the respective text fields. But when I click the save button pID is lost – getting 0 as value so that the insert query always fires.
int pID;
protected void Page_Load(object sender, EventArgs e)
{
pID = Convert.ToInt32(Request["pid"]);
if (pID != 0)
{
if (IsPostBack == false)
{
FillPatientInfo(pID);
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
if(pID ==0)
{
//insert query code
}
else
{
//update query code
}
}
You are not using the QueryString – the code in the JavaScript RedirectToPage() method reads the QueryString and outputs it as form elements and then submits to the target page.
This works fine the first time but as soon as the page posts back the value is lost so this behaviour is correct.
You should either store the value somewhere (ViewState, Session etc) or add a HiddenField to the page and populate it on first load, then on postback you can pull the value from the HiddenField.
Edit
To go the hiddenfield route add a control into your ASPX page like this
And then alter your PageLoad like this