javascript innerHTML not persisting in gridview edit row

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cm9kY2hhcg==?=

    javascript innerHTML not persisting in gridview edit row

    hey all,
    i'm in a gridview edit row that has a DropDownList in one column and a
    status Label in the 2nd column.

    When i changed the value in the dropdownlist, there's a client-side
    javascirpt function that runs and successfully populates label in the 2nd
    column. Everything is fine at this point and working the way it should.

    i do a getElementById to get the status label and then i set its innerHTML
    and again it works fine.

    the problem starts when i try to save the row it the label part does not
    persist but oddly enough the dropdownlist value does save. i try to inspect
    this in debug mode and sure enough the value for the status label is blank.

    shouldn't this persist?

    i also tried this. i manually when into sql and changed the value of the
    status column. i did the same test above and when i tried to save the row
    with the new status value it reverted back to originally what was in the
    database. i'm going to try a smaller scale test to see if it does the same
    thing, but i just thought i'd go ahead and get this one out there.

    thanks,
    rodchar

  • wisccal@googlemail.com

    #2
    Re: javascript innerHTML not persisting in gridview edit row

    Hi Rodchar,

    If I understand you correctly, you set the Label's innerHtml by
    Javascript, and expect that the new value will get picked up by the
    server.

    The problem with this is that you change something without "notifying"
    the server. The ASP.Net engine doesn't expect that a Label gets
    changed, so it will not save those values for you in the way you
    expect. This is different from a DropDownList or a TextBox, both of
    which implement the IPostbackDataHa ndler interface. On postback, only
    server controls that implement this interface will get a chance to
    update their properties on the server side. All other changes that you
    make via Javascript will get lost.

    Since you set the Label's value based on the DropDownList's, I suggest
    that you use the same logic to determine the value that the Label
    should have on postback. Or, if you're on ASP.Net 3.5, just use
    UpdatePanel.

    =============
    Regards,
    Steve


    On Apr 12, 12:09 am, rodchar <rodc...@discus sions.microsoft .com>
    wrote:
    hey all,
    i'm in a gridview edit row that has a DropDownList in one column and a
    status Label in the 2nd column.
    >
    When i changed the value in the dropdownlist, there's a client-side
    javascirpt function that runs and successfully populates label in the 2nd
    column. Everything is fine at this point and working the way it should.
    >
    i do a getElementById to get the status label and then i set its innerHTML
    and again it works fine.
    >
    the problem starts when i try to save the row it the label part does not
    persist but oddly enough the dropdownlist value does save. i try to inspect
    this in debug mode and sure enough the value for the status label is blank.
    >
    shouldn't this persist?
    >
    i also tried this. i manually when into sql and changed the value of the
    status column. i did the same test above and when i tried to save the row
    with the new status value it reverted back to originally what was in the
    database. i'm going to try a smaller scale test to see if it does the same
    thing, but i just thought i'd go ahead and get this one out there.
    >
    thanks,
    rodchar

    Comment

    • =?Utf-8?B?cm9kY2hhcg==?=

      #3
      Re: javascript innerHTML not persisting in gridview edit row

      thank you for the insight,
      rod.

      "wisccal@google mail.com" wrote:
      Hi Rodchar,
      >
      If I understand you correctly, you set the Label's innerHtml by
      Javascript, and expect that the new value will get picked up by the
      server.
      >
      The problem with this is that you change something without "notifying"
      the server. The ASP.Net engine doesn't expect that a Label gets
      changed, so it will not save those values for you in the way you
      expect. This is different from a DropDownList or a TextBox, both of
      which implement the IPostbackDataHa ndler interface. On postback, only
      server controls that implement this interface will get a chance to
      update their properties on the server side. All other changes that you
      make via Javascript will get lost.
      >
      Since you set the Label's value based on the DropDownList's, I suggest
      that you use the same logic to determine the value that the Label
      should have on postback. Or, if you're on ASP.Net 3.5, just use
      UpdatePanel.
      >
      =============
      Regards,
      Steve

      >
      On Apr 12, 12:09 am, rodchar <rodc...@discus sions.microsoft .com>
      wrote:
      hey all,
      i'm in a gridview edit row that has a DropDownList in one column and a
      status Label in the 2nd column.

      When i changed the value in the dropdownlist, there's a client-side
      javascirpt function that runs and successfully populates label in the 2nd
      column. Everything is fine at this point and working the way it should.

      i do a getElementById to get the status label and then i set its innerHTML
      and again it works fine.

      the problem starts when i try to save the row it the label part does not
      persist but oddly enough the dropdownlist value does save. i try to inspect
      this in debug mode and sure enough the value for the status label is blank.

      shouldn't this persist?

      i also tried this. i manually when into sql and changed the value of the
      status column. i did the same test above and when i tried to save the row
      with the new status value it reverted back to originally what was in the
      database. i'm going to try a smaller scale test to see if it does the same
      thing, but i just thought i'd go ahead and get this one out there.

      thanks,
      rodchar
      >
      >

      Comment

      Working...