-->

如何使一个弹出在ASP.Net和使用查询字符串传递信息呢?(How to make a popup

2019-09-30 08:16发布

我有我需要的代码response.redirect页面,并通过我需要其他页面的信息。 但我不希望它重定向的页面,而是建立在页面的弹出。 我有代码的弹出也,但我不能管理将信息传递给它。

这是弹出代码,它不传递任何信息:

<asp:LinkButton ID="lb_viewstudenttimetable" runat="server" OnClick="lb_viewstudenttimetable_Click" 
     OnClientClick="window.open('Timetable_User.aspx','Timetable','width=640,height=360,scrollbars=yes');">

这是代码OnClick按钮,它传递信息到另一个页面

protected void lb_viewstudenttimetable_Click(object sender, EventArgs e)
{
    GridViewRow row = gv_classlist.SelectedRow;
    Response.Redirect("Timetable_User.aspx?UserID=" + row.Cells[1].Text + "");
    //my attempt of trying to pass the following to the popup        
    //Response.Write("window.open('Timetable_User.aspx?UserID="+row.Cells[1].Text+"','Timetable','width=640,height=360,scrollbars=yes');");
}

所以我想用OnClientClick做什么OnClick做。

Answer 1:

只是通过查询字符串:

<asp:LinkButton ID="lb_viewstudenttimetable" runat="server" 
    OnClick="lb_viewstudenttimetable_Click" 
    OnClientClick="window.open('Timetable_User.aspx?UserID=x', 'Timetable', 'width=640,height=360,scrollbars=yes');">

接下来的问题是如何让“X”进入查询字符串时,“X”来自服务器。 你需要做的是,在GridView的数据绑定事件,建立使用的OnClientClick的JavaScript字符串,然后将其设置。 这样一来,每个网格行中的LinkBut​​ton将已经被点击时它准备。



Answer 2:

你想要一个弹出式窗口或新浏览器标签? 如果你想要一个弹出,我一般使用iframe这样。

<a rel="#popupinit" href="#" uniqenum='<%= serversideUniquenum %>'>Open popup</a>

<div style="background-color: white; top: 30px; text-align:center ; width:100%" id="ShowOrderGrid" >
   <iframe id="iframeid" src='' style="width: 500px; text-align:center ; height: 650px;"></iframe>
</div>

<script>
    $(function () {
        $("a[rel='#popupinit]").click(function () {
            var uniquenum = $(this).attr("uniquenum");
            $('#iframeid').attr('src', '/somepath/somepath/somepage.aspx?uniquenum=' + uniquenum);
        });
</script>


Answer 3:

    GridViewRow row = gv_classlist.SelectedRow;
    lbl_timetableuserid.Text = row.Cells[1].Text;


    ScriptManager.RegisterStartupScript(this, typeof(string), "New_Window", "window.open('Timetable_User.aspx?UserID=" + row.Cells[1].Text + "', null, 'height=360,width=640,status=yes,toolbar=yes,menubar=yes,location=no' );", true);


文章来源: How to make a popup in ASP.Net and pass information to it using a query string?