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>");
}
}
