[RESOLVED] Creating simple asp.net control
Hi,
This is my first time with asp.net control, and I guess all I need is a little push, because I'm probably overlooking something pretty simple.
I'm trying to create an asp.net button control that when you click on it, it closes the webpage without having to deal with the dialog box...
"This windows is trying to close, etc"
The code below works, but you have to deal with the dialog box.
code Code:
output.Write("<input type='button' value='close' onclick='javascript: window.close();'></input>")
Here is the code with the javascript part that does not work.
It only wants to execute the first line of the javascript....
window.opener='x'
code Code:
Imports System.ComponentModel
Imports System.Web.UI
<DefaultProperty("Text"), ToolboxData("<{0}:closebutton runat=server></{0}:closebutton>")> Public Class closebutton
Inherits System.Web.UI.WebControls.WebControl
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
output.Write("<input type='button' value='close' onclick='javascript: window.opener='x';window.close();'></input>")
End Sub
Re: Creating simple asp.net control
Quote:
Originally Posted by silentthread
I'm trying to create an asp.net button control that when you click on it, it closes the webpage without having to deal with the dialog box...
"This windows is trying to close, etc"
You cannot.
Oh, you'll find crude workarounds out there that do this that work on just a few versions of a few browsers, but it's a security issue and so is usually not allowed.
Re: Creating simple asp.net control
Thank you for your kind help. I will abandon this project.
Also, incase anyone else reads this thread. I noticed that part of my problem was the fact that IE 7 will not allow the window.opener='x'; trick....
On this plain html page, the close button will work with IE 6 but not IE 7....
Code:
<html>
<head>
<script language='javascript'>
function closeme()
{
window.opener='x';
window.close();
}
</script>
</head>
<body>
<input type="button" value="close" onclick="closeme()"></input>
</body>
</html>
Probably my second problem was that, I needed to modify the code a bit.
I also found out that .net hides certain things from intellisense.
Example... Page.RegisterClientScriptBlock
New code, but will not work with IE7..
code Code:
Imports System.ComponentModel
Imports System.Web.UI
<DefaultProperty("Text"), ToolboxData("<{0}:closebutton runat=server></{0}:closebutton>")> Public Class closebutton
Inherits System.Web.UI.WebControls.WebControl
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
output.WriteBeginTag("input type = 'button'")
output.WriteAttribute("value", "close me")
output.WriteAttribute("onclick", "javascript: closeme();")
output.WriteEndTag("input")
End Sub
Private Sub closebutton_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
'Some hidden properties methods like RegisterClientScriptBlock do not appear in the intellisense....
Page.RegisterClientScriptBlock("closewinKEY", "<script language='javascript'>function closeme(){window.opener='x';window.close();}</script>")
End Sub
End Class
Re: [RESOLVED] Creating simple asp.net control
It would work if you used the Page.RegisterClientScriptBlock call in the Page Load event instead of Render.