2 Replies - 756 Views - Last Post: 26 August 2019 - 11:13 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 634
  • View blog
  • Posts: 4,215
  • Joined: 12-January 10

hidden field persists even after i clear it in code behind

Posted 26 August 2019 - 10:02 AM

so i have a hidden field which tracks missing time.
it is part of an area that has an option to delete a certain field that is part of the calculation for the hidden field.
the issue is when that item is deleted and you add a new row to that item, the hidden field value persists from the previous value.

when i step through the code, the value shows "" which is correct but then when i go to add a new value it shows the old value again.

example:

hf = "-1";
i delete the record that that hidden field is using and the code behind shows hf ="";

i then hit the add button and the code now shows hf="-1";

is there a way to force the script to run again on delete?

 var usedreasonsGV = document.getElementById("MainContent_grdArguments");
    
    if (usedreasonsGV !== null)
    {
        var usedreasonsGVRowlength = usedreasonsGV.getElementsByTagName("tr");
        
        for (var x = 0; x < usedreasonsGVRowlength.length; x++) {
            if (usedreasonsGVRowlength[x].getElementsByTagName("td").length > 0) {

                var usedCtrl =
                    parseInt(usedreasonsGVRowlength[x].cells[3].getElementsByTagName("input")[0].value
                        .replace(',', ''));
                //alert(usedCtrl);
                if ((isNaN(usedCtrl)) || (usedCtrl === '') || (usedCtrl < 1)) {
                    // alert(usedCtrl);
                    //  if (usedCtrl == null) {
                    txtCntrl.focus();
                    alert('Used Reason Minute needs a value or must be greater than 0');
                    usedCtrl.value = 0;
                    usedreasonsGVRowlength[x].cells[3].getElementsByTagName("input")[0].value = 0;

                    return false;

                } else {
                    usedTotal = usedTotal + usedCtrl;
                    roundedUsedTotal = Math.round(usedTotal);

                }

            } else {

                roundedUsedTotal = 0;
            }
            
        }
    }



 <asp:TemplateField headertext="Minutes" HeaderStyle-CssClass="DataGridHeader" >
                                                        <ItemTemplate>
                                                            <asp:TextBox ID="txtMinutesUsed" runat="server" Text='<%# Bind("DTTime")%>'  MaxLength="25" TabIndex="9" onblur="javascript:return GetTotal(this, 'udt');"></asp:TextBox>
                                                        </ItemTemplate> 
                                                    </asp:TemplateField>


  
            UnaccountedMinutes = _HourlyUAccountedMinutes.LoadHourlyProductUnAccountedMinutes(_shiftID,_TransStartTime,Session("PlantID")).ToString()
            if  hfUnaccounted.Value  = ""      
               
                if UnaccountedMinutes > 0 
                    txtUnaccounted.Style.Add("color", "MediumBlue")
                    txtUnaccounted.Text = UnaccountedMinutes.ToString()
                Else 
                    txtUnaccounted.Style.Add("color", "Red")
                    txtUnaccounted.Text = UnaccountedMinutes.ToString()

                End If
          '  _unaccounted = UnaccountedMinutes
          
              hfUnaccounted.Value =   txtUnaccounted.Text
                else
                    txtUnaccounted.Text = hfUnaccounted.Value 
            end if


Is This A Good Question/Topic? 0
  • +

Replies To: hidden field persists even after i clear it in code behind

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15356
  • View blog
  • Posts: 61,566
  • Joined: 12-June 08

Re: hidden field persists even after i clear it in code behind

Posted 26 August 2019 - 10:56 AM

Is it always -1 regardless what value 'hf' was? It may be a hold over from the grid's new row's identity value.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 634
  • View blog
  • Posts: 4,215
  • Joined: 12-January 10

Re: hidden field persists even after i clear it in code behind

Posted 26 August 2019 - 11:13 AM

it's a hold over

i think i got it -- made a button force the routine to run without entering data-- so it now looks at all fields prior to updating---
i just find it weird that the item persisted even when it was cleared everywhere in the code behind and in the javascript... kinda like a hiccup
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1