|
-
Jul 5th, 2004, 02:18 PM
#1
Thread Starter
Frenzied Member
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
-
Jul 6th, 2004, 05:53 AM
#2
PowerPoster
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.
-
Jul 6th, 2004, 08:47 AM
#3
Thread Starter
Frenzied Member
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
-
Jul 6th, 2004, 10:14 AM
#4
PowerPoster
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.
-
Jul 6th, 2004, 10:15 AM
#5
Thread Starter
Frenzied Member
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
-
Jul 6th, 2004, 10:20 AM
#6
PowerPoster
Please post the exact code you have used and the place where you have put it.
-
Jul 6th, 2004, 10:26 AM
#7
Thread Starter
Frenzied Member
<%@ 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
-
Jul 6th, 2004, 10:32 AM
#8
PowerPoster
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.
-
Jul 6th, 2004, 10:36 AM
#9
Thread Starter
Frenzied Member
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
-
Jul 6th, 2004, 10:43 AM
#10
PowerPoster
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.
-
Jul 6th, 2004, 11:12 AM
#11
Thread Starter
Frenzied Member
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
-
Jul 6th, 2004, 02:16 PM
#12
PowerPoster
Well, does it tell you any line thats got the error?
-
Jul 7th, 2004, 05:27 AM
#13
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:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
btnClose.Attributes.Add("onclick", "window.close();")
End If
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.
-
Jul 7th, 2004, 08:38 AM
#14
Thread Starter
Frenzied Member
Don't anthropomorphize computers -- they hate it
-
Jul 7th, 2004, 08:39 AM
#15
Thread Starter
Frenzied Member
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
-
Jul 7th, 2004, 08:49 AM
#16
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.
-
Jul 7th, 2004, 08:52 AM
#17
Thread Starter
Frenzied Member
so the code would run first and then it would close the window?
Don't anthropomorphize computers -- they hate it
-
Jul 7th, 2004, 09:00 AM
#18
No the window will close first then the code will run.
-
Jul 7th, 2004, 09:34 PM
#19
Thread Starter
Frenzied Member
Can I run my own functions using the Attributes.Add?
Don't anthropomorphize computers -- they hate it
-
Jul 8th, 2004, 05:33 AM
#20
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|