javascript innerHTML not persisting in gridview edit row

R

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
 
W

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
 
R

rodchar

thank you for the insight,
rod.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top