Dynamic link in Detailsview disappears on update
-
I have a detailsview showing data from 2 tables. One of the data fields in the detailsview is a link for another page. The link is created using
<a id=.. runat=server target="_blank>..etc
In the Page_Load, I am using code like -DetailsViewRow row = dvParams.Rows[0]; tbox = (TextBox)(row.FindControl("txtEqpID")); anchorSpEquipment = (HtmlAnchor)(row.FindControl("lnkSpEquipment")); anchorSpEquipment.HRef = "....."
It works fine but if edit-update/cancel is clicked, the link goes away, leaving only the text. So, I put the same code above in the detailsview PreRender event handler and it started to work fine. But to edit this field(in edit mode), I have a dropdown list with values populated from another table in the database. To do that - I needed to put code in the PreRenderagain. As soon as I did that, the previous code is giving me null reference on the HtmlAnchor object. I tried to move the code in other EventHandlers like ModeChanging,ItemCommand - but everywhere it does the same...even in the Page_load if I move it outside of the !Page.IsPostBack, it gives the error. Any ideas? Thanks. -
I have a detailsview showing data from 2 tables. One of the data fields in the detailsview is a link for another page. The link is created using
<a id=.. runat=server target="_blank>..etc
In the Page_Load, I am using code like -DetailsViewRow row = dvParams.Rows[0]; tbox = (TextBox)(row.FindControl("txtEqpID")); anchorSpEquipment = (HtmlAnchor)(row.FindControl("lnkSpEquipment")); anchorSpEquipment.HRef = "....."
It works fine but if edit-update/cancel is clicked, the link goes away, leaving only the text. So, I put the same code above in the detailsview PreRender event handler and it started to work fine. But to edit this field(in edit mode), I have a dropdown list with values populated from another table in the database. To do that - I needed to put code in the PreRenderagain. As soon as I did that, the previous code is giving me null reference on the HtmlAnchor object. I tried to move the code in other EventHandlers like ModeChanging,ItemCommand - but everywhere it does the same...even in the Page_load if I move it outside of the !Page.IsPostBack, it gives the error. Any ideas? Thanks.This looks nasty, why not ust define the link in your aspx ?
Christian Graus Driven to the arms of OSX by Vista.
-
This looks nasty, why not ust define the link in your aspx ?
Christian Graus Driven to the arms of OSX by Vista.
-
This looks nasty, why not ust define the link in your aspx ?
Christian Graus Driven to the arms of OSX by Vista.
I got it figured out, thanks Christian. I did this: in the DataBound event handler, to filter the exception - I used if:
if (dvParams.CurrentMode != DetailsViewMode.Edit) { DetailsViewRow row = dvParams.Rows[0]; tbox = (TextBox)(row.FindControl("txtEqpID")); HtmlAnchor anchorSpEquipment = (HtmlAnchor)(row.FindControl("lnkSpEquipment")); anchorSpEquipment.HRef = "~/EquipmentDetails.aspx?Station=" + stationID + "&ColType=" + collType + "&Param=" + paramID + "&ID=" + tbox.Text; }