Question

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.

Was it helpful?

Solution 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);

OTHER TIPS

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.

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top