function callApp() {
            var str = $("#<%=txtAccount.ClientID %>").val();
            var pwd = $("#<%=txtPwd.ClientID %>").val();
            var obj;
            $.post("../Handler/ValidateHandler.ashx", { account: str }, function (data, status) {
                if (status == "success") {
                    if ($.trim(data).toLowerCase() == "false") {
                        obj = document.getElementById("MyFlexApp").flexFun(str);
                        alert("obj:" + obj);
                        $("#<%=hidAccount.ClientID %>").val(obj);//obj值存在,但是给隐藏域之后,我在.cs获取hidAccount的值,却获取不到
                    }
                }
            });
        }

解决方案 »

  1.   

    alert("隐藏域值:"+$("#<%=hidAccount.ClientID %>").val()); 查看隐藏域也赋值成功了
      

  2.   

    不用使用hidAccount.Value来获取,要使用Request.Form["hidAccount"]来获取提交的js赋值的内容,使用hidAccount.Value需要使用viewstate的,js设置的内容没有更新viewstate,所以获取不到
      

  3.   


             $("#<%=btnRegister.ClientID %>").click(function () {
                var account = $("#<%=txtAccount.ClientID %>").val();
                var pwd = $("#<%=txtPwd.ClientID %>").val();
                if (account.length == 0) {
                    $("#spErr").text("请输入用户名!");
                    return false;
                }
                if (pwd.length == 0) {
                    $("#spErr").text("请输入密码!");
                    return false;
                }
                callApp();
            });        function callApp() {
                var str = $("#<%=txtAccount.ClientID %>").val();
                var pwd = $("#<%=txtPwd.ClientID %>").val();
                $.post("../Handler/ValidateHandler.ashx", { account: str }, function (data, status) {
                    if (status == "success") {
                        if ($.trim(data).toLowerCase() == "false") {
                            var result = document.getElementById("MyFlexApp").flexFun(str);
                            $("#<%=hidAccount.ClientID %>").val(result);
                        }
                    }
                });
            }
      

  4.   


            function callApp() {
                var result;
                var str = $("#<%=txtAccount.ClientID %>").val();
                var pwd = $("#<%=txtPwd.ClientID %>").val();
                $.post("../Handler/ValidateHandler.ashx", { account: str }, function (data, status) {
                    if (status == "success") {
                        if ($.trim(data).toLowerCase() == "false") {
                            result = document.getElementById("MyFlexApp").flexFun(str);
                        }
                    }
                });
               alert(result);//弹出undefined, 但是 弹出框之后,点击确定, 赋值却成功了
               $("#<%=hidAccount.ClientID %>").val(result);
            }
      

  5.   

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            TestMembers member = new TestMembers();
            if (!member.Validate(txtAccount.Text))
            {
                member.Account = txtAccount.Text;
                member.Password = EncryptionHelper.MD5(txtPwd.Text);
                member.RegisterTime = DateTime.Now;            member.Add();
                AddLog();
               PrintMessage.PrintClientMessage(Page, "恭喜您,注册成功!");
            }
            else {
                PrintMessage.PrintClientMessage(Page, "用户名已存在!");
            }
        }    private void AddLog() {
            TestMemberLog memberLog = new TestMemberLog();
            memberLog.Account = txtAccount.Text;
            memberLog.AccountCookie = Request.Form["hidAccount"]; //hidAccount.Value
            memberLog.LogTime = DateTime.Now;        memberLog.Add();
        }
      

  6.   

    ajax异步的,你上面的代码肯定是获取不到的,用$.ajax指定为同步提交的  function callApp() {
                var result;
                var str = $("#<%=txtAccount.ClientID %>").val();
                var pwd = $("#<%=txtPwd.ClientID %>").val();
                /*$.post("../Handler/ValidateHandler.ashx", { account: str }, function (data, status) {
                    if (status == "success") {
                        if ($.trim(data).toLowerCase() == "false") {
                            result = document.getElementById("MyFlexApp").flexFun(str);
                        }
                    }
                });*/
    $.ajax({
    url:"../Handler/ValidateHandler.ashx"
    ,async:false///////////同步
    data:{ account: str }, 
    success:function (data, status) {
                    if (status == "success") {
                        if ($.trim(data).toLowerCase() == "false") {
                            result = document.getElementById("MyFlexApp").flexFun(str);
                        }
                    }
                }
    });
               alert(result);//弹出undefined, 但是 弹出框之后,点击确定, 赋值却成功了
               $("#<%=hidAccount.ClientID %>").val(result);
            }没见你提交hidAccount这个控件的代码啊,动态页肯定获取不到了。。