页面无刷新的PostBack事件

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航