aspx How to open one page from within another page

Simon 466 Reputation points
2025-03-12T14:33:11.8866667+00:00

I am Working on ASPX Pages in Visual Stodio with vb.net code

now i am trying to open a page (a from) from within an open page, which code can accomplish this?

Thanks in Advence

Developer technologies ASP.NET ASP.NET API
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. SurferOnWww 4,631 Reputation points
    2025-03-13T03:02:32.2466667+00:00

    How about using a hyperlink (a tag of html) such like:

    <a href="xxx.aspx"
      onclick="window.open(this.href, ...); return false;">
      Open xxx.aspx
      </a>
    

    Please set 2nd and 3rd arguments at ... in window.open(this.href, ...) as required according to the MDN Document Window: open() method.


  2. Anonymous
    2025-03-13T03:39:04.8833333+00:00

    Hi @Simon,

    open a page (a from) from within an open page

    I think you might be looking for something like Bootstrap Modal, where you can add some form controls (eg: TextBox) inside the modal (modal-body).

    Simple code below:

    <head runat="server">
        <title>Modal Test</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" rel="stylesheet" />
        <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script>
    </head>
    <body>
    
        <form id="form1" runat="server">
    
            <!-- Button trigger modal -->
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
                Launch demo modal
            </button>
    
            <!-- Modal -->
            <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true" data-backdrop="static" data-keyboard="false">
                <div class="modal-dialog modal-dialog-centered" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            Box1: 
                            <asp:TextBox runat="server" ID="Name" />
                            <br />
                            Box2:
                            <asp:TextBox runat="server" ID="PWD" />
                        </div>
                        <div class="modal-footer">
                            <button type="submit" class="btn btn-primary">Save</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </body>
    

    If you want to implement this with some existing controls, you can also see if ModalPopupExtender is suitable for you.

    Best regards,

    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2025-03-13T18:09:07.2133333+00:00

    you need to make your requirements clearer. server code can not open a page, only return a response.

    to open a page in a new window/tab you use an anchor.

    <a href="~/newpage.asps" target="_blank">click me</a>
    

    you can use javascript (rendered by the server) to automate:

    <a style="display:none" id="openPage" href="~/newpage.asps" target="_blank">click me</a>
    <script>document.getElementById("openPage").click();<script>
    
    0 comments No comments

  4. Albert Kallal 5,586 Reputation points
    2025-03-15T23:55:01.16+00:00

    In a sense, you don't really "open some page", but in fact navigate to a given page.

    So, say we have a button on FormA.aspx, and we want to open (well, better stated navigate to) FormB.aspx?

    Then our button would be this:

                <asp:Button ID="cmdOpenA" runat="server" Text="Open Page B"
                    OnClick="cmdOpenA_Click"
                    />
    
    

    So, the above would be our button in FormA.aspx. The code behind, to jump to FormB.aspx then could be this:

        Protected Sub cmdOpenA_Click(sender As Object, e As EventArgs)
    
            Response.Redirect("FormB.aspx")
    
        End Sub
    
    

    Now, often, one might include the full path name in the code, so above thus might be:

            Response.Redirect("~/Testing/FormB.aspx") 
    

    So, above would be from the root (start of base site), and then in a folder called Testing, we open the formB.aspx).

    This of course would thus "navigate" to the new page. So, the term "open a page" probably not the best terminology here. Now, perhaps when you click the button, we want to open another browser tab? Again, not a great UI, and think of say when you use this site to ask your question? You click buttons, navigate around - but we not really "opening" new browser tabs, are we?

    So, in web land, the idea of "opening" a page is better stated that we are to click on a button, and "navigate" to another page.

    And that button could even be say inside of a simple Gridview. Say this markup:

        <asp:GridView ID="GHotels" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="ID" CssClass="table table-hover"
            width="40%">
            <Columns>
                <asp:BoundField DataField="FirstName" HeaderText="FirstName"  />
                <asp:BoundField DataField="LastName" HeaderText="LastName"    />
                <asp:BoundField DataField="HotelName" HeaderText="HotelName"  />
                <asp:BoundField DataField="Description" HeaderText="Description"  />
                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                        <asp:Button ID="cmdEdit" runat="server" 
                            Text="Edit" CssClass="btn" 
                            OnClick="cmdEdit_Click" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    
    

    So, in above, we have a standard button. (to edit the row of data).

    So, clicking the button, then we have this effect:

    editonehot

    And the code behind that button?

    this:

        Protected Sub cmdEdit_Click(sender As Object, e As EventArgs)
    
            Dim btn As Button = sender
            Dim gRow As GridViewRow = btn.NamingContainer
            Dim intPK As Integer = GHotels.DataKeys(gRow.DataItemIndex)("ID")
    
            Session("PK") = intPK
            Response.Redirect("EditOneHotel.aspx")
    
        End Sub
    
    

    So, once again, note how we really don't "open" a new form, but better stated is we navigate to that form. The above button code thus gets the current row PK of the database. We then navigate to the 2nd page which displays the hotel, allowing one to edit, or cancel.

    Now, we could for example pop up, or pop open a dialog in place of navigating to the new/difference .aspx page. I tend to prefer this approach, and then the above would look like this:

    popeditnew2

    So, in web land, as opposed to desktop land, the term "open" a page requires more explain on your part. Since it not clear if you want:

    To jump/navigate to a new page when clicking a button.

    Pop open a dialog of some type?

    Open a new tab in the browser?

    You have lots of choices here, but the general idea is that when you click on a button, you can most certainly "jump" or navigate to a difference page, and I suppose could say we are "opening" that new page, but we are in near call cases actually navigating to that new page.

    So for button click code? You just use Response.Redirect("page to jump here")


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.