更改ASP.NET文件中的隐藏字段值并在javascript中获取新值 [英] Change hidden field Value in ASP.NET file and get the new value in javascript
问题描述
Hello
我在ASP.NET中声明了一个隐藏字段,并在选择网格行时在代码隐藏文件中初始化它。
然后我在javascript中为所选行更新了这个隐藏字段。
现在当我移动到下一行时,隐藏值从文件后面的代码改变。但是在javascript文件中,我得到的值与上一行的更新值相同。
C#:
hdnPaxID.Value = string .Join( , ,lstCabins.Select(n = > n.Passenger));
Javascript:
var hdnFieldValue = document .getElementById(' hdnPaxID')。value;
// 更新隐藏字段的一些代码。
请建议。
谢谢!
最有可能,它可能是UpdatePanel问题。在选择行时,您的隐藏字段可能无法更新。
您好Sanjay
我得到了解决方案。
隐藏字段也需要在客户端初始化,即在javascript中。所以在这段代码之后hdnPaxID.Value = string.Join(,,lstCabins.Select(n => n.Passenger));我调用了javascript函数将更新隐藏字段值
function setHiddenFieldValue(hdnPaxID,hdnPaxValue)
{
document.getElementById(hdnPaxID)。 value = hdnPaxValue;
}
所以在我的主要javascript函数中,我可以获得这些更新的值。
结论:如果在客户端使用隐藏字段值,那么它只需要在客户端进行初始化。
我不知道它是如何发生的但它对我有用
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#:
hdnPaxID.Value = string.Join(",", lstCabins.Select(n => n.Passenger));
Javascript:
var hdnFieldValue = document.getElementById('hdnPaxID').value;
//Some code to update hidden field.
Kindly suggest.
Thanks!
Most probably, it may be UpdatePanel issue. Your hidden field may not get updated during selection of rows.
Hi Sanjay
I got the solution.
The hidden fields need to initialize at client side also i.e., in javascript. So after this codehdnPaxID.Value = string.Join(",", lstCabins.Select(n => n.Passenger));I've called javascript function which will update hiddenfield value
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.
这篇关于更改ASP.NET文件中的隐藏字段值并在javascript中获取新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!