javascript innerHTML not persisting in gridview edit row
am 12.04.2008 00:09:00 von rodchar
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
Re: javascript innerHTML not persisting in gridview edit row
am 13.04.2008 18:38:51 von wisccal
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 IPostbackDataHandler 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
www.stkomp.com
On Apr 12, 12:09 am, rodchar
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
Re: javascript innerHTML not persisting in gridview edit row
am 16.04.2008 04:27:01 von rodchar
thank you for the insight,
rod.
"wisccal@googlemail.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 IPostbackDataHandler 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
> www.stkomp.com
>
> On Apr 12, 12:09 am, rodchar
> 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
>
>