Results 1 to 4 of 4

Thread: [RESOLVED] Creating simple asp.net control

  1. #1

    Thread Starter
    Addicted Member silentthread's Avatar
    Join Date
    Jun 2006
    Location
    Miami, Florida
    Posts
    143

    Resolved [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:
    1. 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:
    1. Imports System.ComponentModel
    2. Imports System.Web.UI
    3.  
    4. <DefaultProperty("Text"), ToolboxData("<{0}:closebutton runat=server></{0}:closebutton>")> Public Class closebutton
    5.     Inherits System.Web.UI.WebControls.WebControl
    6.  
    7.     Dim _text As String
    8.  
    9.     <Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
    10.         Get
    11.             Return _text
    12.         End Get
    13.  
    14.         Set(ByVal Value As String)
    15.             _text = Value
    16.         End Set
    17.     End Property
    18.  
    19.  
    20.  
    21.     Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
    22.         output.Write("<input type='button' value='close' onclick='javascript: window.opener='x';window.close();'></input>")
    23.     End Sub
    Last edited by silentthread; Jan 4th, 2008 at 03:10 PM.
    Watch media as you download it! Excellent tool!
    FREE CUBA!
    MyBlog
    If you feel my post has helped, please rate it.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3

    Thread Starter
    Addicted Member silentthread's Avatar
    Join Date
    Jun 2006
    Location
    Miami, Florida
    Posts
    143

    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:
    1. Imports System.ComponentModel
    2. Imports System.Web.UI
    3.  
    4. <DefaultProperty("Text"), ToolboxData("<{0}:closebutton runat=server></{0}:closebutton>")> Public Class closebutton
    5.     Inherits System.Web.UI.WebControls.WebControl
    6.  
    7.     Dim _text As String
    8.  
    9.     <Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
    10.         Get
    11.             Return _text
    12.         End Get
    13.  
    14.         Set(ByVal Value As String)
    15.             _text = Value
    16.         End Set
    17.     End Property
    18.  
    19.  
    20.  
    21.  
    22.     Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
    23.  
    24.         output.WriteBeginTag("input type = 'button'")
    25.         output.WriteAttribute("value", "close me")
    26.         output.WriteAttribute("onclick", "javascript: closeme();")
    27.         output.WriteEndTag("input")
    28.  
    29.     End Sub
    30.  
    31.  
    32.     Private Sub closebutton_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
    33.  
    34.     'Some hidden properties methods like RegisterClientScriptBlock do not appear in the intellisense....
    35.         Page.RegisterClientScriptBlock("closewinKEY", "<script language='javascript'>function closeme(){window.opener='x';window.close();}</script>")
    36.  
    37.     End Sub
    38.  
    39.    
    40. End Class
    Watch media as you download it! Excellent tool!
    FREE CUBA!
    MyBlog
    If you feel my post has helped, please rate it.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

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