How to make a popup in ASP.Net and pass informatio

2019-08-04 01:38发布

I have all the code I need to response.redirect a page and pass the information I need to the other page. But I don't want it to redirect the page but rather create a popup in the page. I have code for the popup also but I can't manage to pass information to it.

This is the code for the popup and it's not passing any information:

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

This is the code for the OnClick button where it passing information to the other page

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

So I wanna use OnClientClick to do what that OnClick does.

3条回答
该账号已被封号
2楼-- · 2019-08-04 02:01
    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);
查看更多
手持菜刀,她持情操
3楼-- · 2019-08-04 02:06

Do you want a pop-up or a new browser tab? If you want a pop up, I generally use iframe like this.

<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>
查看更多
兄弟一词,经得起流年.
4楼-- · 2019-08-04 02:13

Just pass the query string:

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

The question is then how to get "x" into the query string when "x" comes from the server. What you need to do is, in the Databinding event of the GridView, build the JavaScript string to be used OnClientClick, then set it. That way, the LinkButton in each grid row will already be prepared for when it is clicked.

查看更多
登录 后发表回答