页面html代码:
button:<input id="Button5" type="button" value="..."   OnClick="SelUser()" class="bt_daoru" />
<script language="javascript">
function SelUser()
{
    var Url = "CommonFrm.aspx?PageType=1";
    var result=window.showModalDialog(Url,'tempdialog','dialogWidth:400px;status:no;');    
    if(result!=null)
    {
        var val = result.split('$$$');
        document.getElementById("txt_dq").value = val[0];
        document.getElementById("txtbox_gh").value = val[1];
        document.getElementById("txtbox_usern").value = val[2];
        document.getElementById("txtbox_usere").value = val[3];
        document.getElementById("Hidden_mail").value = val[4];
        document.getElementById("Lab_mail").value = val[4];
        document.getElementById("txtbox_zw").value = val[5];
        document.getElementById("txtbox_gs").value = val[6];
        document.getElementById("txtbox_bm").value = val[7];
    }
}页面取值正常,
点button选择您要选择的人员,并取得基本信息赋值给页面。每个值都取到了!页面代码:
namespace WEB
{
    public partial class A_add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
            {
                Response.Redirect("login_index.aspx");
                Response.End();
            }
            if (!IsPostBack)
            {
                check();// 绑定初始人
            }          
        }
        /// <summary>
        /// 绑定初始人
        /// </summary>
        private void check()
        {
            UserInfoModel user = (UserInfoModel)Session["user"];
            this.lab_A_td.Text = user.LoginId;
            this.txtbox_usere.Text = user.LoginId;
            this.txtbox_usern.Text = user.Num.Name;
            this.txtbox_gh.Text = user.Num.Num;
            this.txtbox_gs.Text = user.Num.Gs;
            this.txt_dq.Text = user.Num.Dq;
            this.txtbox_bm.Text = user.Num.Bm;
            this.txtbox_zw.Text = user.Num.Zw;
            this.YYSimpleCalendar1.Text = DateTime.Now.ToString("yyyy-MM-dd");     
        }
       /// <summary>
       /// 添加申请书
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (this.txtbox_why.Text == "")
            {
                Response.Write("<script>alert('事由不能为空!');</script>");
            }
            else if (this.txtbox_th.Text == "")
            {
                Response.Write("<script>alert('申请事项不能为空!');</script>");
            }
            else 
            {
                AModel Amodel = new AModel();
                Amodel.A_date = this.YYSimpleCalendar1.Text;
                Amodel.Number = "A" + Common.StrHelper.GetRamCode();
                Amodel.A_th = this.txtbox_th.Text.Trim();
                Amodel.A_why = this.txtbox_why.Text.Trim();
                Amodel.A_sl = this.txtbox_sl.Text.Trim();
                Amodel.A_mon = this.txtbox_fy.Text.Trim();
                Amodel.A_qia = this.txtbox_qia.Text.Trim();
                Amodel.A_cw = this.txtbox_cw.Text.Trim();
                Amodel.A_tel = this.txtbox_tel.Text.Trim();
                Amodel.A_unum = this.txtbox_gh.Text.Trim();
                Amodel.A_usern = this.txtbox_usern.Text.Trim();
                Amodel.A_usere = this.txtbox_usere.Text.Trim();
                Amodel.A_gs = this.txtbox_gs.Text.Trim();
                Amodel.A_dq = this.txt_dq.Text.Trim();
                Amodel.A_bm = this.txtbox_bm.Text.Trim();
                Amodel.A_zw = this.txtbox_zw.Text.Trim();
                Amodel.A_zwd = "";
                Amodel.A_fj = this.txtbox_tel.Text.Trim();
                Amodel.A_td = this.lab_A_td.Text.Trim();
                Amodel.A_dd = DateTime.Now;
                Amodel.A_dm = "";
                ABLL abll = new ABLL();
                if (abll.Add_A(Amodel) > 0)
                {
                    Response.Write("<script>alert('添加成功!');location.href='Get_User2.aspx';</script>");
                }
                 else
                {
                    Response.Write("<script>alert('添加失败!');location.href='Get_User2.aspx';</script>");
                }
            }
        }
    }
}这里也正常!绑定登录者初始人也没问题!
就是最后添加成功后,总是添加到是初始人信息,
就是要是选择了其他人员(基本信息也都取到没问题,txtbox显示。)
最后添加成功后,还是添加到是初始人信息!不知道为什么?

解决方案 »

  1.   

    这个问题早有人问过了,Label用js赋值后,在后台根本取不到新值,因为viewstate没有改变。如果textbox的属性readonly为true的话,用js赋值后,在后台任然取不到新值,因为viewstate也没有改变。
      

  2.   

    你用ICallbackEventHander接口吧,直接无刷新更新。不用担心cs取值的问题
      

  3.   

    也可以用hiddenfiled保存数据,或者将textbox的readonly属性去掉。
      

  4.   

    海风你好,能否说的具体点,我在网上查了一些ICallbackEventHander资料。
    就是不知咋写?
    …………………………………………………………………………………………………………
    “无刷新页面”,只是一种不确切的效果描述(其实还有其他各种方法来实现这个效果),更确切的说法是:在页面上用JavaScript调用服务器端的一个方法,然后处理返回的数据。实现它最标准的方法当然是XMLHTTP。但是,程序员都是懒惰的家伙,每个人都希望能有更方便的方法,或者,更佳的包装。比如,Lostinet的Rane就是对XMLHTTP的一个很好的包装。终于,在ASP.NET 2.0里面,我们可以轻松的来做到这点了。服务器端任何实现了System.Web.UI.ICallbackEventHandler接口的控件,都可以通过RaiseCallbackEvent()方法来处理从页面上的JS脚本传递过来的请求和数据,处理后,再将结果传回给页面。这项能力的底层仍然是XMLHTTP。下面是一个简单的演示:在页面上,我们放上两个文本框和一个按钮:
    <INPUT id="txtMessage">
    <INPUT onclick="callToServer();" type="button" value="Call to Server">
    Result : <INPUT id="txtResult" >当点击按钮的时候,将调用JS脚本方法callToServer(),JS脚本如下:
    function callToServer()
    {
        var param = document.getElementById("txtUsername").value;
        var context = ""; 
        <% = ClientScript %>
    }function handleResultFromServer(result, context)
    {
        document.getElementById("txtResult").value = result;
    }handleResultFromServer()方法则负责将从服务器传回的数据写到txtResult这个文本框里面。再看看服务器端的代码:public partial class Default_aspx : System.Web.UI.ICallbackEventHandler
    {
        private String ClientScript
        {
            get
            {
                return this.GetCallbackEventReference(this, "param", "handleResultFromServer", "context");
            }
        }    public string RaiseCallbackEvent(string eventArgument)
        {
            return "客户端在[" + DateTime.Now.ToString() + "]传送来 [" + eventArgument + "].";
        }
    }我们让页面直接实现ICallbackEventHandler接口,然后接口定义的RaiseCallbackEvent()方法中将服务器的时间和传来的数据一起返回回去。ClientScript属性的作用是,它调用了页面的GetCallbackEventReference()方法,获得了让客户端有能力调用服务器端方法的JS脚本,并输出到页面的callToServer()方法中,这样,点击页面按钮时,就开始执行页面上包含了调用服务器方法的的callToServer()方法。注意GetCallbackEventReference()方法的参数,在参数中,我们定义了客户端的哪个变量包含了要传递给服务器,服务器方法执行后,调用客户端的哪个方法等信息。GetCallbackEventReference()的详细参看请看这里。
    ………………………………………………………………………………………………………………………
      

  5.   

    感谢各位大侠,能否说的具体点呢?
    意思我知道了,就是不知怎么写!当我通过js改变textbox值时,如何将textbox值写到数据库里?
    而不是总是写入我在后台给textbox的初始Session值呢!
    ICallbackEventHander无刷新页面,怎么用?
      

  6.   

    直接在后台写个绑定的函数。或者用楼上说的用javascript函数呀。不知道你绑定啥控件呢。也不知道你想啥歌哦能呢。
      

  7.   

    这是我写的一些代码,你对比着在原基础上添加和修改下。这里使用ICallbackEventHandler接口1.在你的前台添加js
    <script language="javascript">
          function submit()
          {
          document.getElementById("Button1").value="提交中..."
          //前台数据传到后台处理
            var arg = document.getElementById("txt_dq").value
                                    +"$$$"+document.getElementById("txtbox_gh").value
                                    +"$$$"+document.getElementById("txtbox_usern").value
                                    +"$$$"+document.getElementById("txtbox_usere").value
                                    +"$$$"+document.getElementById("Hidden_mail").value
                                    +"$$$"+document.getElementById("Lab_mail").value
                                    +"$$$"+document.getElementById("txtbox_zw").value
                                    +"$$$"+document.getElementById("txtbox_gs").value
                                    +"$$$"+document.getElementById("txtbox_bm").value;
              
              //返回后台处理后的数据到前台,用前台函数ReceiveServerData来接收
            <%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData",null)%>;
          }
          function ReceiveServerData(arg)
          {
          if(arg=="ok")
             document.getElementById("Button1").value="提交成功"
             else
             document.getElementById("Button1").value="提交失败"
         }
    </script>2.在html代码中添加:
    <input id="Button1" type="button" value="提交"   onclick="submit()"  />3.继承ICallbackEventHandler接口
    public partial class A_add : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler4.实现接口中静态方法:
        private string CallBackValue = string.Empty;
        //引发回调事件处理
        void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
        {
            string arg = eventArgument;//接受前台js传进来的参数arg
            string[] array = arg.Split(new string[] { "$$$" });
            //这里调用你的方法fun(),
            //fun();
            CallBackValue = "ok";    }    //回传回调结果
        string ICallbackEventHandler.GetCallbackResult()
        {
            return CallBackValue;
            
        }要点基本都有了,你先看看。
      

  8.   

    大致能理解,就还是不知怎么写?一下是我参考你的和在网上看的写的,<script language="javascript">
    function callback(){
        var Url = "CommonFrm.aspx?PageType=1";
        var result=window.showModalDialog(Url,'tempdialog','dialogWidth:400px;status:no;');
        if (result != null) {
            var val = result.split('$$$');
            document.getElementById("txt_dq").value = val[0];
            document.getElementById("txtbox_gh").value = val[1];
            document.getElementById("txtbox_usern").value = val[2];
            document.getElementById("txtbox_usere").value = val[3];
            document.getElementById("Hidden_mail").value = val[4];
            document.getElementById("Lab_mail").value = val[4];
            document.getElementById("txtbox_zw").value = val[5];
            document.getElementById("txtbox_gs").value = val[6];
            document.getElementById("txtbox_bm").value = val[7];
            dos(val[0] + "&" + val[1] + "&" + val[2] + "&" + val[3] + "&" + val[4] + "&" + val[5] + "&" + val[6] + "&" + val[7])
            //dos(name + "&" + pass + "&" + checkcode);     
        }
    }
    function ReceiveServerData(text) {
        alert(text);
        location.href = location.href;
    }
    </script>  public partial class A_add : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
        {
            private string result;        protected void Page_Load(object sender, EventArgs e)
            {
                if (Session["user"] == null)
                {
                    Response.Redirect("login_index.aspx");
                    Response.End();
                }
                if (!IsPostBack)
                {
                    check();// 绑定初始人
                    //string cbReference = Page.ClientScript.GetCallbackEventReference(this, "text", "ReceiveServerData");//获取一个对客户端函数的引用;调用该函数时,将启动一个对服务器端事件的客户端回调。
                   // string callbackScript = "function dos(text){" + cbReference + ";}";//客户端方法
                    //Page.ClientScript.RegisterClientScriptResource(this.GetType(), "dos", callbackScript, true);
                }          
            }
            /// <summary>
            /// 处理回调事件。 
            /// </summary>
            /// <param name="text"></param>
            public void RaiseCallbackEvent(string text)
            {
                string[] j = text.Split(new char[] { '&' }, 7);
                string callbackScript = "function dos(text){" + Page.ClientScript.GetCallbackEventReference(this, "text", "ReceiveServerData") + ";}";//这里报错:方法没有采用“3”个参数的重载
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "dos", callbackScript, true);
                this.txt_dq.Text=j[0];
                this.txtbox_gh.Text=j[1];
                this.txtbox_usern.Text=j[2];
                this.txtbox_usere.Text=j[3];
                this.Hidden_mail.Value=j[4];
                this.txtbox_zw.Text=j[5];
                this.txtbox_gs.Text=j[6];
                this.txtbox_bm.Text=j[7];        }
            /**/
            /// <summary>
            /// 返回回调事件的结果。 
            /// </summary>
            /// <returns></returns>
            public string GetCallbackResult()
            {
                return result;
            }
            /*
            //引发回调事件处理
            private void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
            {
                string arg = eventArgument;//接受前台js传进来的参数arg
                string[] array = arg.Split(new char[] { '&' }, 8);
                //这里调用你的方法fun(),
                //fun();
                CallBackValue = "ok";        }
            //回传回调结果
            private string ICallbackEventHandler.GetCallbackResult()
            {
                return CallBackValue;        }*/        /// <summary>
            /// 绑定初始人
            /// </summary>
            private void check()
            {
                UserInfoModel user = (UserInfoModel)Session["user"];
                this.lab_A_td.Text = user.LoginId;
                this.txtbox_usere.Text = user.LoginId;
                this.txtbox_usern.Text = user.Num.Name;
                this.txtbox_gh.Text = user.Num.Num;
                this.txtbox_gs.Text = user.Num.Gs;
                this.txt_dq.Text = user.Num.Dq;
                this.txtbox_bm.Text = user.Num.Bm;
                this.txtbox_zw.Text = user.Num.Zw;
                this.YYSimpleCalendar1.Text = DateTime.Now.ToString("yyyy-MM-dd");
               
            }
           /// <summary>
           /// 添加申请书
           /// </summary>
           /// <param name="sender"></param>
           /// <param name="e"></param>
            protected void Button2_Click(object sender, EventArgs e)
            {
                if (this.txtbox_why.Text == "")
                {
                    Response.Write("<script>alert('事由不能为空!');</script>");
                }
                else if (this.txtbox_th.Text == "")
                {
                    Response.Write("<script>alert('申请事项不能为空!');</script>");
                }
                else 
                {
                    AModel Amodel = new AModel();
                    Amodel.A_date = this.YYSimpleCalendar1.Text;
                    Amodel.Number = "A" + Common.StrHelper.GetRamCode();
                    Amodel.A_th = this.txtbox_th.Text.Trim();
                    Amodel.A_why = this.txtbox_why.Text.Trim();
                    Amodel.A_sl = this.txtbox_sl.Text.Trim();
                    Amodel.A_mon = this.txtbox_fy.Text.Trim();
                    Amodel.A_qia = this.txtbox_qia.Text.Trim();
                    Amodel.A_cw = this.txtbox_cw.Text.Trim();
                    Amodel.A_tel = this.txtbox_tel.Text.Trim();
                    Amodel.A_unum = this.txtbox_gh.Text.Trim();
                    Amodel.A_usern = this.txtbox_usern.Text.Trim();
                    Amodel.A_usere = this.txtbox_usere.Text.Trim();
                    Amodel.A_gs = this.txtbox_gs.Text.Trim();
                    Amodel.A_dq = this.txt_dq.Text.Trim();
                    Amodel.A_bm = this.txtbox_bm.Text.Trim();
                    Amodel.A_zw = this.txtbox_zw.Text.Trim();
                    Amodel.A_zwd = "";
                    Amodel.A_fj = this.txtbox_tel.Text.Trim();
                    Amodel.A_td = this.lab_A_td.Text.Trim();
                    Amodel.A_dd = DateTime.Now;
                    Amodel.A_dm = "";
                    ABLL abll = new ABLL();
                    if (abll.Add_A(Amodel) > 0)
                    {
                        Response.Write("<script>alert('添加成功!');location.href='Get_User2.aspx';</script>");
                    }
                     else
                    {
                        Response.Write("<script>alert('添加失败!');location.href='Get_User2.aspx';</script>");
                    }
                }
            }
        }
      

  9.   

    我发现我把这些控件都改成
    Enabled=true
    就可以了!
    但是这些人员的基本信息是不可以改的,所以我又想把它们设为false。
    不知还有什么其他办法
      

  10.   

    这是帮你写的的,测试通过,你再根据你的需求加工下,注释的部分是你要提交到数据库的操作。<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
       <script language="javascript">
    function SelUser()
    {
        var Url = "CommonFrm.aspx?PageType=1";
        var result=window.showModalDialog(Url,'tempdialog','dialogWidth:400px;status:no;');    
        if(result!=null)
        {
            var val = result.split('$$$');
            document.getElementById("txt_dq").value = val[0];
            document.getElementById("txtbox_gh").value = val[1];
            document.getElementById("txtbox_usern").value = val[2];
            document.getElementById("txtbox_usere").value = val[3];
            document.getElementById("Hidden_mail").value = val[4];
            document.getElementById("Lab_mail").value = val[4];
            document.getElementById("txtbox_zw").value = val[5];
            document.getElementById("txtbox_gs").value = val[6];
            document.getElementById("txtbox_bm").value = val[7];
        }
    }
          function CallBack()
          {
          document.getElementById("Button1").value="提交中..."
          //前台数据传到后台处理
            var arg = document.getElementById("txt_dq").value 
                            +"$$$"+document.getElementById("txtbox_gh").value
                            +"$$$"+document.getElementById("txtbox_usern").value
                             +"$$$"+document.getElementById("txtbox_usere").value
                             +"$$$"+document.getElementById("Hidden_mail").value
                             +"$$$"+document.getElementById("Lab_mail").value
                             +"$$$"+document.getElementById("txtbox_zw").value
                             +"$$$"+document.getElementById("txtbox_gs").value
                             +"$$$"+document.getElementById("txtbox_bm").value;
            alert(arg);
              
              //返回后台处理后的数据到前台,用前台函数ReceiveServerData来接收
            <%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData",null)%>;
          }
          function ReceiveServerData(arg)
          {
            if(arg=="ok")
             document.getElementById("Button1").value="提交成功"
             else
             document.getElementById("Button1").value="提交失败"
         }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:TextBox ID="txt_dq" runat="server" ReadOnly="true">111</asp:TextBox>
            <asp:TextBox ID="txtbox_gh" runat="server" ReadOnly="true">222</asp:TextBox>
            <asp:TextBox ID="txtbox_usern" runat="server" ReadOnly="true">333</asp:TextBox>
            <asp:TextBox ID="txtbox_usere" runat="server" ReadOnly="true">444</asp:TextBox>
            <asp:TextBox ID="Hidden_mail" runat="server" ReadOnly="true">555</asp:TextBox>
            <asp:TextBox ID="Lab_mail" runat="server" ReadOnly="true">666</asp:TextBox>
            <asp:TextBox ID="txtbox_zw" runat="server" ReadOnly="true">777</asp:TextBox>
            <asp:TextBox ID="txtbox_gs" runat="server" ReadOnly="true">888</asp:TextBox>
            <asp:TextBox ID="txtbox_bm" runat="server" ReadOnly="true">999</asp:TextBox><input id="Button5" type="button" value="赋值"   onclick="SelUser()" class="bt_daoru" />
    <input id="Button1" type="button" value="提交"   onclick="CallBack()"  />    </form>
    </body>
    </html>public partial class A_add: System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
            {
                Response.Redirect("login_index.aspx");
                Response.End();
            }
            if (!IsPostBack)
            {
                check();// 绑定初始人
            }
        }
        /// <summary>
        /// 绑定初始人
        /// </summary>
        private void check()
        {
            UserInfoModel user = (UserInfoModel)Session["user"];
            this.lab_A_td.Text = user.LoginId;
            this.txtbox_usere.Text = user.LoginId;
            this.txtbox_usern.Text = user.Num.Name;
            this.txtbox_gh.Text = user.Num.Num;
            this.txtbox_gs.Text = user.Num.Gs;
            this.txt_dq.Text = user.Num.Dq;
            this.txtbox_bm.Text = user.Num.Bm;
            this.txtbox_zw.Text = user.Num.Zw;
            this.YYSimpleCalendar1.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }
        /// <summary>
        /// 添加申请书
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>    private string CallBackValue = string.Empty;
        //引发回调事件处理
        void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
        {
            string arg = eventArgument;
            string[] array = arg.Split(new string[] { "$$$" }, StringSplitOptions.RemoveEmptyEntries);        //这里进行你的操作,array数组里面是前台发过来的数据,可以在下面绑定到AModdel上。        /*AModel Amodel = new AModel();
            Amodel.A_date = this.YYSimpleCalendar1.Text;
            Amodel.Number = "A" + Common.StrHelper.GetRamCode();
            Amodel.A_th = this.txtbox_th.Text.Trim();
            Amodel.A_why = this.txtbox_why.Text.Trim();
            Amodel.A_sl = this.txtbox_sl.Text.Trim();
            Amodel.A_mon = this.txtbox_fy.Text.Trim();
            Amodel.A_qia = this.txtbox_qia.Text.Trim();
            Amodel.A_cw = this.txtbox_cw.Text.Trim();
            Amodel.A_tel = this.txtbox_tel.Text.Trim();
            Amodel.A_unum = this.txtbox_gh.Text.Trim();
            Amodel.A_usern = this.txtbox_usern.Text.Trim();
            Amodel.A_usere = this.txtbox_usere.Text.Trim();
            Amodel.A_gs = this.txtbox_gs.Text.Trim();
            Amodel.A_dq = this.txt_dq.Text.Trim();
            Amodel.A_bm = this.txtbox_bm.Text.Trim();
            Amodel.A_zw = this.txtbox_zw.Text.Trim();
            Amodel.A_zwd = "";
            Amodel.A_fj = this.txtbox_tel.Text.Trim();
            Amodel.A_td = this.lab_A_td.Text.Trim();
            Amodel.A_dd = DateTime.Now;
            Amodel.A_dm = "";
            ABLL abll = new ABLL();
            if (abll.Add_A(Amodel) > 0)
            {
                CallBackValue = "ok";
            }*/
        }
        //回传回调结果
        string ICallbackEventHandler.GetCallbackResult()
        {
            return CallBackValue;
        }
    }