技术开发 频道

实现Asp.net中弹出窗口中选择值

  【IT168 技术文档】在Asp.net中,从A页面中弹出B页面,在B页面中选择数据后,关闭并将数据更新到A页面,是一种常用的方式。只是我对Javascript不熟悉,所以捣鼓了一下午,终于有了一点成绩。

  测试项目有两个页面:Default.aspx及Default2.aspx,在Default.aspx页面上有一个TextBox1及一个Button1,Button1用于触发Default2.aspx,TextBox1用于接收从子页面传回的值。

  Button1的代码如下:

  以下为引用的内容:
  

StringBuilder s = new StringBuilder();
  s.Append(
" ");
  Type cstype
= this.GetType();
  ClientScriptManager cs
= Page.ClientScript;
  
string sname = "lt";
  
if (!cs.IsStartupScriptRegistered(cstype, sname))
  cs.RegisterStartupScript(cstype, sname, s.ToString());

  Default2.aspx页面内有一个CheckBoxList1及一个Button1,Button1执行返回选择的CheckBoxList1的值,并将当前页面关闭。

  代码如下:

  以下为引用的内容:
  

protected void Button1_Click(object sender, EventArgs e)
  {
  StringBuilder s
= new StringBuilder();
  s.Append(
" ");
  Type cstype
= this.GetType();
  ClientScriptManager cs
= Page.ClientScript;
  
string csname = "ltype";
  
if (!cs.IsStartupScriptRegistered(cstype, csname))
  cs.RegisterStartupScript(cstype, csname, s.ToString());
  }
  
private string GetSelectValue()
  {
  
string rvalue = "";
  
for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
  {
  
if (this.CheckBoxList1.Items[i].Selected)
  {
  
if (rvalue == "")
  rvalue
+= this.CheckBoxList1.Items[i].Text;
  
else
  rvalue
+= "," + this.CheckBoxList1.Items[i].Text;
  }
  }
  
return rvalue;
  }
0
相关文章