Results 1 to 20 of 20

Thread: Closing web page

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Closing web page

    Hey,

    I have a web page (web form) that is displaying an image.
    I want to close it using a button as well.
    What command closes the current web form?

    Thanks,
    Don't anthropomorphize computers -- they hate it

  2. #2
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    You will have to use client-side javascript to close the window

    Code:
    <script language="JavaScript">
    function CloseWin()
    {
    window.close();
    }
    </script>
    In you HTML you will need to call this ClientSideScript on the onClick event of the button, you want to use as the close button

    Code:
    <input type="button" text="Close" onClick="javascript:CloseWin();" ID="BtnClose"
    >
    edit: fixed the previous typos in the word - code
    Last edited by veryjonny; Jul 6th, 2004 at 10:34 AM.

  3. #3

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    Thanks.
    However, I'm using VS.NET to develop the web page.
    It tells me that java script is not a member of that page.
    Am I doing something wrong?

    Also, are there any web resources to learn Java script?
    It seems that asp alone isn't sufficient to do some neat stuff. (mouse overs, etc..)

    THanks,
    Don't anthropomorphize computers -- they hate it

  4. #4
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    You will need to edit the HTML code and add that javascript in it.

    The javascript is not to be added in the - say - webform1.aspx.vb, file, it should be added in the webform1.aspx file.

    When inthe desgin mode, click on the HTML button (lower left hand side corner) and enter the above code in it.

  5. #5

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    That's what I've done. However, it does not work.
    It tells me that java script is not a memeber of the web form.

    Thanks,
    Don't anthropomorphize computers -- they hate it

  6. #6
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Please post the exact code you have used and the place where you have put it.

  7. #7

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="Tester.WebForm2"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>WebForm2</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <code>
    <script language= javascript>
    function CloseWin()
    {
    window.close();
    }
    </script>
    </code>
    <form id="Form1" method="post" runat="server">
    <asp:Button onclick= "javascript:CloseWin()" id="Button1" style="Z-INDEX: 101; LEFT: 315px; POSITION: absolute; TOP: 132px" runat="server"
    Text="Button"></asp:Button>
    </form>
    </body>
    </HTML>
    Don't anthropomorphize computers -- they hate it

  8. #8
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    1. I am sorry for the typos in my first post

    2. please do the following

    I have deleted the <code></code> words because, it was teh foramtting i need here in vbforums and not for teh HTML page.

    Second, I have placed teh script block inside the <HEAD> tag

    Thrid: removed teh space from between the words "java" and script in the onclick event

    Code:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="Tester.WebForm2"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>WebForm2</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <script language= javascript>
    function CloseWin()
    {
    window.close();
    }
    </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    
    <form id="Form1" method="post" runat="server">
    <asp:Button onClick= "javaScript:CloseWin();" id="Button1" style="Z-INDEX: 101; LEFT: 315px; POSITION: absolute; TOP: 132px" runat="server"
    Text="Button"></asp:Button>
    </form>
    </body>
    </HTML>
    Last edited by veryjonny; Jul 6th, 2004 at 10:36 AM.

  9. #9

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    Thanks,

    I get the following error:

    Compiler Error Message: BC30456: 'java' is not a member of 'ASP.WebForm2_aspx'

    this is really weird.
    Don't anthropomorphize computers -- they hate it

  10. #10
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    please remove all spaces between the words "java" and "script"

    It should be ONE word : JavaScript.

    I accidentally started a new thread, trying to reply to this thread.

  11. #11

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    I have tried that as well.
    Same error except it says that javascript is not a member of web form.aspx.

    The other time it said java (I guess it omits anything after the space)

    Thanks,
    Don't anthropomorphize computers -- they hate it

  12. #12
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Well, does it tell you any line thats got the error?

  13. #13
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    If you don't need the button to run any server side code just use a html button instead
    Code:
    <input type="button" id="btnclosewin" onclick="javascript:closewin();" value="Close window">
    Not sure why but i can't get the above line to appear without a space between java and script just remove it.

    Otherwise if you do also want to run server side code aswell as the javascript you can use an <asp:button> like this.
    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         If Not IsPostBack Then
    3.             btnClose.Attributes.Add("onclick", "window.close();")
    4.         End If
    5.     End Sub

    EDIT: NOTE:Unless you opened the window yourself the browser will display a confirmation box asking the user if they want the page to close.
    Last edited by Fishcake; Jul 7th, 2004 at 05:36 AM.

  14. #14

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    thanks dude.
    Don't anthropomorphize computers -- they hate it

  15. #15

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    I was just wondering,

    If I add the 'onclick' attribute, would it overwrite any code that is the routine handling the onclick event for the button?

    thanks,
    Don't anthropomorphize computers -- they hate it

  16. #16
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    Nope any code behind your button would still run.

    Though perhaps depending on the javascript as you could add an OnClick attribute that displayed a JS confirmation box and then your code would only run if the user selected Yes/ok but not if they selected no/cancel.

  17. #17

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    so the code would run first and then it would close the window?
    Don't anthropomorphize computers -- they hate it

  18. #18
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    No the window will close first then the code will run.

  19. #19

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    Can I run my own functions using the Attributes.Add?
    Don't anthropomorphize computers -- they hate it

  20. #20
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    Have a read of this MSDN article it should clear things up for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width