Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have declared one hidden field in ASP.NET and initialize its value in code behind file during selection of grid row.
Then I have updated this hidden field in a javascript for that selected row.
Now when I moved to next row, the hidden value gets changed from code behind file. But in javascript file I am getting the same value which was updated for previous row.

C#:
C#
hdnPaxID.Value = string.Join(",", lstCabins.Select(n => n.Passenger));


Javascript:
JavaScript
var hdnFieldValue = document.getElementById('hdnPaxID').value;
//Some code to update hidden field.


Kindly suggest.
Thanks!
Posted
Comments
Thanks7872 17-Mar-15 10:10am    
As you have not explained how you are processing different rows, its not clear what the issue is. Make sure that you are selecting data from the proper row.

Apply class to hiddenfields. And in javascript find that field using class, not Id.

Most probably, it may be UpdatePanel issue. Your hidden field may not get updated during selection of rows.
 
Share this answer
 
Hi Sanjay

I got the solution.
The hidden fields need to initialize at client side also i.e., in javascript. So after this code
hdnPaxID.Value = string.Join(",", lstCabins.Select(n => n.Passenger));
I've called javascript function which will update hiddenfield value
C#
function setHiddenFieldValue(hdnPaxID, hdnPaxValue)
{
    document.getElementById(hdnPaxID).value = hdnPaxValue;
}


So in my main javascript function, I can get these updated value.
Conclusion: If hiddenfield value to be use at client side then it needs to initialize at client side only.

I don't know how it happens but it works for me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900