ASP隐藏域上使用jQuery在服务器端没有更新的价值 [英] Asp hidden field not updating value on the server side using jQuery

查看:172
本文介绍了ASP隐藏域上使用jQuery在服务器端没有更新的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个隐藏字段:

<ContentTemplate>
<asp:HiddenField ID="hiddenId" runat="server"/>
</ContentTemplate>

和jQuery的:

var emptyVal = "123";

$("[id*=gridview] td").bind("click", function () {
var row = $(this).parent();
$("[id*=gridview] tr").each(function () {
if ($(this)[0] != row[0]) {
    $("td", this).removeClass("");
}
});
if (!$(this).hasClass("")) {
    $(this).addClass("");
}
else 
{
    $(this).removeClass("");
    $('#<%= hiddenId.ClientID %>').val(emptyVal);
    alert($('#<%= hiddenId.ClientID %>').val());
}

在code背后:

The code behind:

var value = hiddenId.Value;

我添加了一个的onclick 事件上的GridView控件的行的RowDataBound

I added an onclick event on the rows of the gridview on the rowdatabound:

e.Row.Attributes.Add("onclick","javascript: getElementById('" + hiddenId.ClientID + "').value='" + e.Row.RowIndex + "';");

因此​​,该行的每一次点击,该行的索引被存储在隐藏字段。

So on every click of the row, the row index is being stored on the hidden field.

在这里我的问题是我无法在服务器端的新值。我用jQuery开发的警报来测试,如果该值被更新。它正在更新,但是当它击中断点在服务器端,我仍然得到旧值。

My problem here is I can't get the new value on the server side. I used the alert on the jquery to test if the value is being updated. It is being updated but when it hit the breakpoint on the server side, I still get the old value.

我甚至用这个,但仍然没有运气的尝试:

I even tried using this but still no luck:

var hiddenValue = Request.Form[hiddenId.UniqueID];

我能做些什么,所以我可以从隐藏字段的新值?谢谢!

What can I do so I can get the new value from the hidden field? Thanks!

编辑:

的目的的jQuery 是突出所选的GridView的行。当再次点击同一行,它会删除该行的重头戏。并在同一时间,应该从隐藏字段中删除该值。

The purpose of the jQuery is to highlight the row of the selected gridview. Upon clicking again the same row, it will remove the highlight of the row. And at the same time, it should remove the value from the hidden field.

示例场景:

1)用户会点击一行结果
2)隐藏字段将 INT 填充0为例。结果
3)当用户再次点击同一行,它会删除的隐藏字段的值。

1) User will click a row
2) The hidden field will be populated by int 0 for example.
3) When the user click the same row again, it will remove the value of the hidden field.

推荐答案

我解决我的问题,通过使用下面的code:

I solved my problem by using the code below:

var hiddenValue = Request.Form[hiddenId.Value];

这篇关于ASP隐藏域上使用jQuery在服务器端没有更新的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆