How do you open a window on the same page?
(response.redirect will go to the other page.)
Thanks.

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Select Case DropDownList1.Text
            Case "First Meeting Room"
                Response.Redirect("http://localhost:52952/RoomSetting/FirstMeetingRoom.aspx", False)
            Case "Second Meeting Room"
                Response.Redirect("http://localhost:52952/RoomSetting/MainMenu.aspx", False)
        End Select
    End Sub

Dani AI

Generated

Short answer: to keep the current page visible and open another browser window or tab, run client-side code (for example window.open) rather than using Response.Redirect. If the new UI should appear inside the same page, use a modal or an iframe (as suggested).

A simple client-side approach tied to the DropDownList avoids a postback and pop-up blocking:

<script>
function openRoom(url) {
  if (!url) return;
  window.open(url, '_blank', 'width=900,height=700,resizable=yes,scrollbars=yes');
}
</script>
' Add this once (e.g. Page_Load) to have the select open the URL on change
DropDownList1.Attributes.Add("onchange", "openRoom(this.value);")

If you must decide server-side in SelectedIndexChanged, emit a client script that calls window.open. Use ScriptManager.RegisterStartupScript when you have partial postbacks (UpdatePanel); otherwise ClientScript.RegisterStartupScript works:

Dim url As String = ResolveUrl("~/RoomSetting/FirstMeetingRoom.aspx")
Dim script As String = String.Format("window.open('{0}','_blank','width=800,height=600');", url)

If ScriptManager.GetCurrent(Page) IsNot Nothing Then
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "openWin", script, True)
Else
    ClientScript.RegisterStartupScript(Page.GetType(), "openWin", script, True)
End If

Notes and caveats: pop-up blockers may block windows unless opened as a direct user action, so the pure client-side onchange method is most reliable. For a better UX consider showing the room page inside a modal (via Bootstrap/jQuery UI) with an iframe if you want the “window” visually within the same page. See the browser API docs for window.open and the ASP.NET script registration methods for details: Window.open (MDN), ScriptManager.RegisterStartupScript (Microsoft), .

Recommended Answers

All 2 Replies

Sorry, I need to get a bit more info out of you...

When you say "open a window on the same page" to what are you referring?

Yes, Response.Redirect will make a call to the browser to go to the new URL provided similar to clicking a link in a webpage would.

If you are trying to have the contents appear as a subset of the page that you are showing the rest of your content in you may need to look into frames or dynamic display methods available via ASP.Net (panels, divs, etc).

I'm sorry if I'm not understanding what you're looking for but the concept of a Response Redirect effect that doesn't redirect to a new page's content is not clicking for me at the moment :twisted:

Sorry, I need to get a bit more info out of you...

When you say "open a window on the same page" to what are you referring?

Yes, Response.Redirect will make a call to the browser to go to the new URL provided similar to clicking a link in a webpage would.

If you are trying to have the contents appear as a subset of the page that you are showing the rest of your content in you may need to look into frames or dynamic display methods available via ASP.Net (panels, divs, etc).

I'm sorry if I'm not understanding what you're looking for but the concept of a Response Redirect effect that doesn't redirect to a new page's content is not clicking for me at the moment :twisted:

on the page to open a window, the page still there, but a window is opened,when clicked. this is my question, Response.Redirect is to open a new page, right, but I want the page is still there, on the page just will open a new window when a clicked. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.