日期:2009-06-16  浏览次数:20388 次

TextBox的onchange事件会引起页面重新刷新,这使得输入很不方便,于是我想了以下的解决办法。
思路:1、调用简单的前台脚本打开一个新页, 2、把相关参数传递给该新页处理(该新页的前后台均可处理), 3、处理后所得数据再用前台脚本返回opener, 4、数据处理完毕后被打开的页面自动关闭。代码例:要处理的页面send.ASPx:

string windowAttribs = "width=10px," + "height=10px," + "left='+((screen.width +" + "10" + ") * 2)+'," + "top='+ (screen.height + " + "10" + ") * 2+'";

TextBox2.Attributes["onchange"] = "var aaa = this.value;window.open('open_XML.ASPx?get_id=TextBox2&get_value='+aaa,'open_test','"+windowAttribs+"')";

TextBox3.Attributes["onchange"] = "var aaa = this.value;window.open('open_page.ASPx?get_id=TextBox3&get_value='+aaa,'open_test','"+windowAttribs+"')";

打开的页面open_page.ASPx:
private void Page_Load(object sender, System.EventArgs e)

{

object ls_o1 = Request.QueryString["get_id"].ToString();

object ls_o2 = Request.QueryString["get_value"].ToString();

if(ls_o1 != null && ls_o2 != null)

{

get_id.Value = (string)ls_o1;

get_value.Value = (string)ls_o2;

}

send_value_back();

}



private void send_value_back()

{

if(get_id.Value != "" && get_value.Value != null)

{

this.Response.Write("<script language=javascript>window.opener.Form1."+get_id.Value+".value='aaaaaaaaaaaa'"+"</script>");

this.Response.Write("<script language=javascript>window.opener=null;window.close();</script>");

}

}