您的位置:程序门 -> .net技术 -> asp.net



再次开贴,页面中值回传的问题!急~~请高手解答.


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


再次开贴,页面中值回传的问题!急~~请高手解答.[已结贴,结贴人:lsp69]
发表于:2007-07-09 11:21:15 楼主
碰到了这样一种怪情况:
在父窗体中放了两个文本框: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事件,我该怎么处理?
发表于:2007-07-09 11:34:081楼 得分:20
page_load时赋值给textbox7.text= " ";试试。
发表于:2007-07-09 11:35:332楼 得分:0
其实lz大可不必这样,直接用js写不是更省事?!!
发表于:2007-07-09 11:39:243楼 得分:30
这个是因为,b/s下的textbox,它的textchanged事件是服务器端事件,不像c/s下,任何字符动作都会触发,它只在离开textchanged时,引发autopostback。
也就是说,当你第二次从另一窗口选择数据时才autopost,即触发该事件

你在选了数据后,手动为textbox7移除焦点,试一下行不行
发表于:2007-07-09 11:54:154楼 得分:0
写的太复杂,


快速检索

最新资讯
热门点击