【问题标题】:Transferring values from popup page to parent page将值从弹出页面传输到父页面
【发布时间】:2012-04-05 05:53:27
【问题描述】:

我有一个父页面 inner4.aspx 和一个弹出页面 popupemail.aspx 。现在发生的事情是我在弹出窗口中提取电子邮件 ID 并在网格视图中显示,当用户选择电子邮件 ID 时,它会通过 javascript 函数转移到父页面。

家长代码:

function setText1(txt) {
            document.getElementById('TextBox4').value = txt;
        }

弹出代码:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        //TextBox2.Text = row.Cells[1].Text;


        ScriptManager.RegisterStartupScript(this,GetType(), "settxt", "setText1('"+ row.Cells[1].Text + "');", true);
    }

值没有被传输。 请帮忙

【问题讨论】:

  • 你能不能只写一个简单的警报,看看函数是否正在运行,也基于你设置 id 的方式,确保你有客户端模式静态

标签: javascript asp.net c#-4.0


【解决方案1】:

将修改后的行复制到您的代码中

ScriptManager.RegisterStartupScript(this,GetType(), "settxt", "window.opener.setText1('"+ row.Cells[1].Text + "');", true);

【讨论】:

  • 它没有用。我应该从更新面板中删除 gridview 吗??
  • 你可以尝试添加调试器吗?并在调试模式(F5)下运行项目,例如ScriptManager.RegisterStartupScript(this,GetType(), "settxt", "debugger;window.opener.setText1('"+ row.Cells[1].Text + "');", true);并检查光标是否在调试器处停止;如果它没有停止,则意味着您的整个脚本没有被调用
【解决方案2】:

你可以通过使用javascript调用父页面

window.opener.document.getElementById("TextBox4").value = txt;

或者你可以通过同样的方式调用父页面函数

window.opener.setText();

setText() 函数写在父页面而不是弹出页面。

【讨论】:

    【解决方案3】:

    否则在选定的索引更改后,在服务器端设置一些属性

    in the cs
    protected string SelectedValue{
       get {
          return "whatever";
       }
    }
    
    
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = GridView1.SelectedRow;
            //TextBox2.Text = row.Cells[1].Text;
    
    
            SelectedValue = row.Cells[1].Text
        }
    
    in the js
    $(document).ready(function(){
        var selectedValue= '<%=SelectedValue%>';
        window.opener.document.getElementById("TextBox4").value = selectedValue;
    
    });
    

    可能存在语法错误。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 2014-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多