刚刚接触c#,有这样的需求,不知道该怎么实现
具体如下,请大家帮忙看看
Textbox1,在textBox1中输入 1123AA
然后将1123作为参数传递给Texbox2,这样可以获取到,但是要将获取到的1123作为一个参数调用关于的方法就不行了,具体代码如下:   string str = this.Cus_id.Text;//这个是获取Textbox1中的文本值
       CustomerBLL Scinfo = new CustomerBLL();调用相关业务逻辑方法
       IList<Customer> ISC = Scinfo.GetinfoBywhere(" Id=" + Convert.ToInt32(str));
       foreach (Customer sc in ISC)
       {
           this.qty.Text = sc.name_EN;
}
可能我的业务逻辑有点问题,具体的需求就是当textbox1的onkeyup事件出发后,获取textbox1中的参数值,将其传递给textbox2,但是textbox2中显示的不是获取到的参数的值,而是这个参数经过相关的方法后的值..请大家赐教,谢谢

解决方案 »

  1.   

    TextChanged事件里面写 protected void txtMoney_TextChanged(object sender, EventArgs e)
        {
            if(this.TextBox1.Text.Trim()!="")
            this.TextBox2.Text=this.TextBox1.Text;
        }
      

  2.   

    首先要设置文本框的AutoPostBack属性。
      

  3.   

    textchanged刷新比较不爽,这种情况用ajax比较好
      

  4.   

    可以用textbox的Onchange事件,但是要设置Textbox1的Autopostback属性为true. asp.net服务器端事件必须postback后才能触发。
    protected void TextBox1_TextChanged(object sender, EventArgs e)
            {
                TextBox2.Text = TextBox1.Text;
            }
      

  5.   

    你可以吧Text放入UpdatePanel里面就行了。
      

  6.   

    ls,好像你没有理解我的需求,将textbox1的值传递给textbox2可以做到,主要是要将textbox1中的值作为参数,经过一个方法后,再来给textbox2赋值
      

  7.   

    this.Textbox1.Attributes.Add("onblur", "Set(this.value);");
     function Set(str) {
        document.getElementById("Textbox2").value=str;
    }
      

  8.   

    string str = this.Cus_id.Text
    CustomerBLL Scinfo = new CustomerBLL
    IList<Customer> ISC = Scinfo.GetinfoBywhere("Id=" + Convert.ToInt32(str));
    foreach (Customer sc in ISC)
     {
         this.qty.Text = sc.name_EN;
    }
    方法没问题,ISC 是否有值 
      

  9.   

    你的文本框设置了AutoPostBack为True了没有。。向这种情况的话。建议才用ajax实现。效果可能会更好一点。
      

  10.   

    这个问题还用C#?直接一个Javascript算了吧
    function getValues(){
    document.getElementById("<%=TextBox2.ClientID%>").value=document.getElementById("<%=TextBox1.ClientID%>").value;
    }<asp:TextBox ID="TextBox2" runat="server" onchange="getValues();"/>
      

  11.   

    楼主你的最好还是用AJAX来做。我想效果会很好。关于AJAX的资料,楼主可以去网上找。
      

  12.   

    ajax js 你做出来就是正道
      

  13.   

     function creatXMLHTTP()
     {
      var xmlhttp=null;
      try{xmlhttp=new XMLHttpRequest();}
      catch(MSIEx){
        try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
        catch(e){
          try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
         catch(e)
         {alert("您的浏览器不支持ajax!");}
         }
        }
        return xmlhttp;
     
     }
    function  getinfo()
     {
      with(document.form1)
      {
       if(TextBox1.length==0) {return;}
      
       var id=TextBox1.value;
       var x=creatXMLHTTP();
       var url='Ajaxcodeget.aspx?id='+id+'&s='+ new Date().getTime();
       x.open('GET',url,true);
       x.onreadystatechange = function(){
      if (x.readyState == 4 && x.status == 200) {
    //alert(xmlHttp.responseText);
    var s = x.responseText;
    textbox2.value=s;
     }
    }
    x.send(null); 
     } 
    }2.Ajaxcodeget.aspx
    在pageload事件里面获取传递过来的参数:
     if (Request.QueryString["id"]!="")//判断传递的参数是否为空
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                 //写具体的方法
                  ....
                string s=...
                response.write(s);
                response.End();

      
                       }