我有一张表select id,name from aa 还有一张页面。此页面使用了母板页 页面上有两个textbox1 textbox2 我想根据textbox1输入的内容,当textbox1失去焦点后,从数据库中读取相对应的name值 放进textbox2中 要求不刷新页面,要局部刷新,因为页面中还有其他东西

解决方案 »

  1.   

    你在生成的页面上打开源代码找到你的textbox1 textbox2 真正的ID值。
    而后用Jquery Ajax作局部刷新
      

  2.   

    你们说的我都知道,AJAX控件不能用,我有固定布局格式的,,请你们给我代码,关键就是不知道怎么写呀
      

  3.   

    那就用JQuery。比如你的母版页上面textbox1的id就是textbox1,生成的html代码中的id应该是ctl00_ContentPlaceHolder1_textbox1
    用Jquery            
                $('#ctl00_ContentPlaceHolder1_textbox1').blur(function(){
                    $.ajax({
                        type: 'POST',
                        data: {
                            key: escape(key)
                        },
                        dataType: 'json',
                        url: 'json.ashx',
                        beforeSend: function(XMLHttpRequest){
                            $('#ctl00_ContentPlaceHolder1_textbox2').val('加载中');
                        },
                        success: function(data){
    $('#ctl00_ContentPlaceHolder1_textbox2').val(data.name);
                        },
                        complete: function(XMLHttpRequest){                    }
                    })
                })
      

  4.   

    试试把textbox1,textbox2放在两个不同的iframe中,当textbox1失去焦点是做个提交查询。然后刷新textbox2,把查询的值赋给textbox2。
      

  5.   

    test.html:
    <input id=txt1 onblur="getpara(this);"/><input id=txt2 />
    <script>
    function getpara(obj){
        if(obj.value.length==0){return;}//Nullの場合、処理終了  
        var id=obj.value;
        var xmlHttp=createXMLHttpRequest();
        url='photo3.aspx?id='+id+'&s='+ new Date().getTime();
        xmlHttp.open('GET',url,true);
        xmlHttp.onreadystatechange=function(){homel(xmlHttp)};
        xmlHttp.send(null);
        //debugger;
    }function homel(x){
        if (x.readyState==4){
            if(x.status==200||x.status==0){
                document.getElementById("txt2").value=x.responseText;
            }
        }
    }
    function createXMLHttpRequest() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            try {
                return new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e2) {
                    return null;
                }
            }
        } else {
            return null;
        }
    }</script>
    photo3.aspx:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
    <% dim Session
    dim db 
    dim rs
    dim sql
        Dim id

        id = Request.QueryString("id")
    Session = Server.CreateObject("OracleInProcServer.XOraSession")
    db = Session.DbOpenDatabase("database","uid/psd",0)
    sql="Select name From aa where id=" & id
    rs = db.CreateDynaset(sql,0)
        
        Response.ContentType = "text/xml"
        
        If Not rs.Eof Then
            Response.Write(rs("name").value)
        End If
        
        rs.Close
        db.close
        db=nothing
        Session = Nothing
        
        Response.End()
    %>