What is the code to close page in VB?

Last post 11-05-2009 11:20 PM by atconway. 7 replies.

Sort Posts:

  • What is the code to close page in VB?

    10-18-2009, 9:26 PM
    • Member
      174 point Member
    • hkbeer
    • Member since 07-03-2008, 12:07 AM
    • Posts 651

    I want if textbox1.text = "close" then the page/browser windows is closed.

    What should be the code in VB ?

    Thanks

     

    Thanks in advance for the help. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped.
  • Re: What is the code to close page in VB?

    10-18-2009, 11:52 PM
    Answer
    U can do it with the help of javascript . call the below snippet in any user define function it will close the page , the url u give in page_name.aspx 
    Response.Write("<script language="javascript">") Response.Write("window.close('page_name.aspx')") Response.Write("</script>")


     

    22.Net
  • Re: What is the code to close page in VB?

    10-19-2009, 5:54 AM
    • Member
      174 point Member
    • hkbeer
    • Member since 07-03-2008, 12:07 AM
    • Posts 651

    Thanks. Exactly where I should put this code ?

    In <script> section or in pageload event ?

    Pls help...

     

    Thanks in advance for the help. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped.
  • Re: What is the code to close page in VB?

    10-19-2009, 6:57 AM

    If u put it in coding section that is in .vb file then write it as it is i posted

    if u want to put in .aspx file then in head section enclose it in <script> tags

     

    22.Net
  • Re: What is the code to close page in VB?

    10-19-2009, 7:01 AM

    like this

    <script>

    function close(var url)

    {

    window.close('page_name.aspx');

    }

    </script>

    then call this javascript function in any event u want to close the window for xample in link u can write like ,  OnClick = 'close(page_name)' like this ok

    if still not solved then please inform ok

     

    22.Net
  • Re: What is the code to close page in VB?

    10-19-2009, 10:19 AM
    • Contributor
      5,894 point Contributor
    • atconway
    • Member since 09-24-2007, 9:20 PM
    • Florida U.S.A
    • Posts 1,234

    Here is an example of how to do this based on your needs:

    1st: the example code for the .aspx page:

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
        <script type="text/javascript">
        
           //Closes the browser window
           function CloseWindow() 
           {
              window.opener = 'x';
              window.close();
           }
              
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
           <asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
           <asp:Button ID="brnSubmit" runat="server" Text="Submit" />
        </div>
        </form>
    </body>
    </html>

     

    2nd, the code for the .vb behind the page:

        Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
    
            'See if the word 'close' was input by the user:
            '(converting user input to lower case to handle for case differences which we do not care about)
            If Me.txtInput.Text.Trim().ToLower() = "close" Then
                'Automatically close the page using JavaScript
                ClientScript.RegisterStartupScript(Me.GetType(), "script", "CloseWindow();", True)
            End If
    
        End Sub


    Hope this helps! Smile

    Thank you,   >[Blog]<

    "The best thing about a boolean is even if you are wrong, you are only off by a bit." :D
    -anonymous

  • Re: What is the code to close page in VB?

    11-05-2009, 11:17 PM
    • Member
      91 point Member
    • mhinkle2
    • Member since 01-18-2009, 3:56 AM
    • Posts 153

    It's still not closing the page.  I put this in the renderpage complete section.  Also tried it in the Load complete.  I used the vb verison.

    I need the page to load, produce the tif file and then close. Please help. 

  • Re: What is the code to close page in VB?

    11-05-2009, 11:20 PM
    • Contributor
      5,894 point Contributor
    • atconway
    • Member since 09-24-2007, 9:20 PM
    • Florida U.S.A
    • Posts 1,234

     mhinkle2 -

    Make sure to post this comment back on your original post and not on the link I provided.

     

    Thank you,   >[Blog]<

    "The best thing about a boolean is even if you are wrong, you are only off by a bit." :D
    -anonymous

Page 1 of 1 (8 items)