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

jquery 来访问后台方法 取不到值得问题
HTML code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title></title>
   <script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script>
   <script language="javascript" type="text/javascript">
   $(document).ready(function () {
   $("#HiddenField1").val("aaa");
   alert($("#HiddenField1").val());
   });
   function ReduceSerching() {
   htmlobj = $.ajax({ url: "WebForm1.aspx", async: false });
   alert(htmlobj.responseText);
   }
   </script>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   <input id="Hidden1" type="hidden" runat="server" />
   <asp:HiddenField ID="HiddenField1" runat="server" />
   <input id="Button1" type="button" value="button" onclick="javascript:ReduceSerching()" />
   </div>
   </form>
</body>
</html>






C# code


protected void Page_Load(object sender, EventArgs e)
   {
   Response.Write(HiddenField1.Value);[color=#FF0000]为什么这就取不到值呢,死活都取不到,跪求解答555555[/color]
   }



------解决方案--------------------
Page_Load的时候,你的组件中还没有被写入内容吧,他会先于你的jquery方法执行