日期:2014-05-18  浏览次数:20406 次

再次开贴,页面中值回传的问题!急~~请高手解答.
碰到了这样一种怪情况:
在父窗体中放了两个文本框:TextBox1和TextBox7,其中:AutoPostBack= "True ",一个按扭:Button3,当我点击
Button3时弹出一个选择数据的窗体:
Button3.Attributes.Add( "onclick ", "window.open   ( 'f_FoodSelect.aspx ',   '信息列表 ',   'height=400,   width=758,   top=180,left=180,toolbar=no,   menubar=no,   scrollbars=yes,   resizable=no,location=no,   status=no ');   ");  
我在f_FoodSelect.aspx中选择了数据后回传回父窗体中的TextBox7,代码如下:
private   void   DataGrid1_DeleteCommand(object   source,   System.Web.UI.WebControls.DataGridCommandEventArgs   e)
{
DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;

string   s_id=e.Item.Cells[1].Text.ToString();
Response.Write( " <script> ");
Response.Write( "window.opener.document.Form1.TextBox7.value= ' "+s_id.Replace( " ' ", "\ " ")+ " '; ");
Response.Write( "window.close(); ");
Response.Write( "window.close(); ");
Response.Write( " </script> ");
}

在父窗体中我触发这样的事件:
private   void   TextBox7_TextChanged(object   sender,   System.EventArgs   e)
{
TextBox1.Text=TextBox7.Text;
}
问题是这样的:
  为什么我第一次选择数据后不会触发TextBox7_TextChanged事件,而要选择第二次后才会触发TextBox7_TextChanged事件?
我要第一次选择数据后就触发TextBox7_TextChanged事件,我该怎么处理?


------解决方案--------------------
Page_load时赋值给TextBox7.Text= " ";试试。
------解决方案--------------------
这个是因为,B/S下的TextBox,它的TextChanged事件是服务器端事件,不像C/S下,任何字符动作都会触发,它只在离开TextChanged时,引发AutoPostBack。
也就是说,当你第二次从另一窗口选择数据时才AutoPost,即触发该事件

你在选了数据后,手动为TextBox7移除焦点,试一下行不行