1. 程式人生 > >TextBox內容發生改變時觸發的事件

TextBox內容發生改變時觸發的事件

方法一:不推薦

1. 前臺textbox屬性AutoPostBack="true";

2.後臺

        protected void Page_Init(object sender, EventArgs e)
        { 
            txtVehicleNum.TextChanged += new EventHandler(txtVehicleNum_TextChanged);
        }
        void txtVehicleNum_TextChanged(object sender, EventArgs e)
        { 
            DangerClassDataBind();
        }  

方法二:不推薦  

1.後臺

        protected void Page_Init(object sender, EventArgs e)
        { 
            txtVehicleNum.Attributes["OnBlur"] = ClientScript.GetPostBackEventReference(btnTemp, null);  
        }
        void btnTemp_Click(object sender, EventArgs e)
        {
            DangerClassDataBind();
        }
方法三:推薦

1.js:

//選擇車輛
            function openSelectVehicleWindow() {
                var returnValue = window.showModalDialog("VehicleInfo_Select.aspx", window, "dialogWidth:1000px; dialogHeight:500px; status:no; directories:yes;scrollbars:no;Resizable=no;help=no");

                if (returnValue != null) {
                    var strvalue = returnValue.split('|'); 
                    document.getElementById("<%=txtVehicleNum.ClientID %>").value = strvalue[0];
                    document.getElementById("<%=txtPlateColor.ClientID %>").value = strvalue[1];
                    document.getElementById("<%=txtPlateColorName.ClientID %>").value = strvalue[2];

                    document.getElementById("btnTemp").click();
                }
            }
2.後臺
       void btnTemp_Click(object sender, EventArgs e)
        {
            DangerClassDataBind();
        }