日期:2014-05-17  浏览次数:20373 次

Lable赋值后数据丢失问题
我的lbl_count赋值后,执行JS时数据就为null了, 求大神指教。
lbl_count.Text = Request.QueryString["count"].ToString();

<asp:Label ID="lbl_count" runat="server" Visible="false"></asp:Label>


  $('#<%=txt_count.ClientID %>').blur(function(){
                $("#<%=lbl_remain.ClientID %>").html("剩余" + parseInt($("#<%=lbl_remain.ClientID %>").html())-parseInt($("#<%=lbl_count.ClientID %>").html())+"本书");
                alert($("#<%=lbl_count.ClientID %>").html());
            });

结果显示:NaN本书
数据 label asp js 数据丢失

------解决方案--------------------
visible="false"的控件没被渲染成html标记,只是被记录在viewstate中了
------解决方案--------------------
$("#<%=lbl_count.ClientID %>")这个东西根据不存在,被你parseInt后自然就是NAN了
不要想当然,visible="false"后,html中就没那控件了
用asp:Label ID="lbl_count" runat="server" style="display:none"></asp:Label>还说得过去