Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dynamic link in Detailsview disappears on update

Dynamic link in Detailsview disappears on update

Scheduled Pinned Locked Moved ASP.NET
databasesysadminhelpquestionannouncement
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Ekjon
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • E Ekjon

      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.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This looks nasty, why not ust define the link in your aspx ?

      Christian Graus Driven to the arms of OSX by Vista.

      E 2 Replies Last reply
      0
      • C Christian Graus

        This looks nasty, why not ust define the link in your aspx ?

        Christian Graus Driven to the arms of OSX by Vista.

        E Offline
        E Offline
        Ekjon
        wrote on last edited by
        #3

        I tried that as well - and it's giving me the same error. Is there any other way? Thanks.

        1 Reply Last reply
        0
        • C Christian Graus

          This looks nasty, why not ust define the link in your aspx ?

          Christian Graus Driven to the arms of OSX by Vista.

          E Offline
          E Offline
          Ekjon
          wrote on last edited by
          #4

          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; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups