很实用的一个方法,在此记录备忘

page1.aspx.cs

protected void Page_Load(object sender, EventArgs e)//页面载入时给按钮注册一个js事件,当点击按钮时打开新页面
 {
            string js = "javascript:w=window.open('page2.aspx?Name="+ this.TextBox1.ClientID +"')";
            this.Button1.Attributes.Add("onclick", js);
}

page2.aspx.cs

protected void Button1_Click(object sender, EventArgs e)//点击按钮时获取URL传来的控件ID,把要得到到的值赋给传来的URL
{
            string name = Request.QueryString["Name"].ToString();
            string value = ((Button)sender).CommandArgument.ToString();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", GetNameTextAndValueToOpener(name,value),true);
}

public string GetNameTextAndValueToOpener(string name,string value)
{
            string js = "winOpener=window.self.opener;winOpener.document.getElementById('"+ name +"').value='"+ value +"';window.close();";
            return js;
}

相关文章:

  • 2021-07-09
  • 2021-12-19
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
猜你喜欢
  • 2021-07-31
  • 2022-01-15
  • 2021-08-07
  • 2022-12-23
  • 2021-12-29
  • 2021-12-13
  • 2021-11-16
相关资源
相似解决方案