open several new pages on button click

Last post 09-15-2009 5:17 AM by Shengqing Yang - MSFT. 8 replies.

Sort Posts:

  • open several new pages on button click

    09-14-2009, 2:27 AM
    • Member
      496 point Member
    • Roba
    • Member since 11-17-2008, 7:29 AM
    • Posts 182

     hi,

    i have a situation on which i want to open several pages on one button click

    i has three checkboxes and one button ...for every checkbox i choose i have to open a new page when i click the button ...is there a way i can do such an approach ?

    thanks in advance

  • Re: open several new pages on button click

    09-14-2009, 5:56 AM

    In the click event handler of the button, check which pages should be open and call a javascript function to open these pages using window.open() function

    You can call this javascript function using RegisterClientScriptBlock function

    Please Mark As Answer if my post helps you
    Thanks
  • Re: open several new pages on button click

    09-14-2009, 11:42 PM
    Answer

    Roba:

    Hi,

    i have a situation on which i want to open several pages on one button click

    i has three checkboxes and one button ...for every checkbox i choose i have to open a new page when i click the button ...is there a way i can do such an approach ?

    thanks in advance

    Hi,

    We can easily use JavaScript function to achieve this task. Please refer to the demo below to see if it meets your requirement.

    <%@ Page Language="VB" %>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function openForm() {
                if (document.getElementById("CheckBox1").checked == 1)
                    window.open("http://www.bing.com");
                if (document.getElementById("CheckBox2").checked == 1)
                    window.open("http://www.google.com");
                if (document.getElementById("CheckBox3").checked == 1)
                    window.open("http://www.msn.com");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:CheckBox ID="CheckBox1" runat="server" />www.bing.com<br />
            <asp:CheckBox ID="CheckBox2" runat="server" />www.google.com<br />
            <asp:CheckBox ID="CheckBox3" runat="server" />www.msn.com<br />
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="openForm();" />
        </div>
        </form>
    </body>
    </html>

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
  • Re: open several new pages on button click

    09-15-2009, 2:28 AM
    • Member
      496 point Member
    • Roba
    • Member since 11-17-2008, 7:29 AM
    • Posts 182

     Well i tried your way but when i click the button nothing happens .......plz help

    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="CLPrTranID.aspx.vb" Inherits="CLprtranID"
        MasterPageFile="~/MasterPage.master" Title="PreTrans" Culture="en-GB" %>

    <asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1" >
        <div style="height: 354px; margin-top: 28px;">

    <asp:CheckBox ID="ClmStatus" runat="server"
                    style="position :absolute; top: 81px; left: 650px;" />
                <asp:CheckBox ID="Info" runat="server"
                    style="position :absolute; top: 51px; left: 650px;" AutoPostBack="True" />
                <asp:CheckBox ID="MRpt" runat="server"
                    style="position :absolute; top: 21px; left: 650px;" Checked="True" />
    <asp:Button ID="Prt" runat="server" Text="Print Transaction"
                    style="position : absolute; top: 334px; left: 18px; width: 134px; margin-top: 0px;"
                    Font-Bold="True"  OnClientClick="openForm();"/>
    </div>
         <script type="text/javascript" language="javascript"  >
             function openForm()
            {
                if (document.getElementById("MRpt").checked == 1)
                    window.open("CLReport.aspx?type=M");
                if (document.getElementById("Info").checked == 1)
                    window.open("CLReport.aspx?type=I&ClmTrs=" & document.getElementById("ClmTrs"));
                if (document.getElementById("ClmStatus").checked == 1)
                    window.open("CLReport.aspx?type=S");
            }  
        </script> 

    </asp:Content>

  • Re: open several new pages on button click

    09-15-2009, 2:33 AM
    Answer
    • Contributor
      6,003 point Contributor
    • vijayst
    • Member since 12-19-2008, 10:49 AM
    • Posts 1,219

     In your javascript, use document.getElementByID("<%= Mrpt.ClientID %>")

    This is because your checkbox is rendered within a content control. and the ids rendered in HTML will change.

    -Vijay
    My blog: www.VijayT.com
  • Re: open several new pages on button click

    09-15-2009, 3:28 AM

    Hi Roba,

    In your code

    if (document.getElementById("MRpt").checked == 1).

    Instead of double quotes use single quote. then it will work

    if (document.getElementById('MRpt').checked == 1)

         window.open("CLReport.aspx?type=M");

    Also make sure that the pages CLReport.aspx already exists

    Please click "Mark as Answer" if you think this post answer your question

    Best Regards,
    Suresh Kumar Gundala
  • Re: open several new pages on button click

    09-15-2009, 3:53 AM
    • Participant
      1,547 point Participant
    • ashish-1983
    • Member since 09-14-2009, 7:29 AM
    • Posts 512

    it should work..

    can u tell us wot is an error?

    Please remember to click "Mark as Answer" on the post that helps you.
  • Re: open several new pages on button click

    09-15-2009, 4:03 AM
    • Member
      496 point Member
    • Roba
    • Member since 11-17-2008, 7:29 AM
    • Posts 182

     thanks ,

    seems that this detail made it work

    :D thank you very much

  • Re: open several new pages on button click

    09-15-2009, 5:17 AM

    Roba:

    thanks,

    seems that this detail made it work

    :D thank you very much

    Hi,

    That's all right. Just as a note, the reason why your previous code didn't work is you used it in a Content Page. When the page runs, the JavaScript cannot find the CheckBox by its original name in a Content Page.

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
Page 1 of 1 (9 items)