日期:2014-05-18  浏览次数:20554 次

asp.net 后面获取Label值的问题
C# code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <script src="js/jquery-1.4.1.js" type="text/javascript"></script>
      <script type="text/javascript">
          $(function () {
              $("#Button1").click(function () {
                  var sumall = 33;
                  $("#Label14").text(sumall);                 
              })
          })
      </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Button1" type="button" value="button" />
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>


在后台用Label1.Text获取的值为空的,为什么呢?

------解决方案--------------------
例子
<%@ Page Language="C#" %>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (Request.RequestType == "POST")
{
Response.Write(HiddenField1.Value);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#Button1").click(function () {
var sumall = 33;
$("#Label14").text(sumall);
$("#HiddenField1").val(sumall);
$("#form1").submit();
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" />
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>
</form>
</body>
</html>