Masterpage - window.showModalDialog - window.close

Discussion in 'ASP .Net' started by kurt sune, Aug 18, 2008.

  1. kurt sune

    kurt sune Guest

    Hello, I have a weird problem, I hope someone can explain this for me.

    I have a webpage using masterpage.
    In it I create a popup window using this code:
    Dim js As String = "<script language=javascript>"

    js &= "var newWin = window.showModalDialog('InkommetVi.aspx"

    js &= "',null,"

    js &= "'center:yes; resizable:yes;help:no;dialogHeight:600px;
    dialogWidth:750px;edge: Raised;status: No;');"

    js &= "</script> "

    Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "InkommetV", js)



    The popup window gets displayed all right.

    The popup window has a close button declared thus:

    <asp:Button ID="btnClose" runat="server" Text="Close" />

    And in it's clickevent I try to close the window: Response.Write("<script
    language='javascript'> {window.close();}</script>")



    It doesn't work.

    I have tried with these: (they work on pages not using masterpage)

    ClientScript.RegisterStartupScript(Me.GetType(), "cwin", "window.close();")

    Response.Write("<script language='javascript'> {window.opener = 'x';
    window.close();}</script>")

    Response.Write("<script language='javascript'> {window.opener = '';
    window.close();}</script>")

    Response.Write("<script language='javascript'> {this.focus();self.opener =
    this;self.close();}</script>")

    Response.Write("<script language='javascript'> {top.window.opener =
    top;top.window.open('','_parent','');top.window.close();}</script>")

    Response.Write("<script language='javascript'>
    {window.open('','_self');window.close();}</script>")

    Response.Write("<script language='javascript'> {window.opener = self;
    window.close();}</script>")

    Dim sScript As String = "<SCRIPT language='javascript'> "

    sScript &= "window.close();"

    sScript &= "</SCRIPT>"

    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "InkommetVi",
    sScript)



    Neither of them works.



    What does work however is this code on the page:

    <script type="text/javascript">

    window.onunload=st;

    function st()

    {

    window.close();

    }

    </script>

    <input id="Button1" type="button" value="Close" onclick="st();" />





    Can anybody explain this to me?



    /k
    kurt sune, Aug 18, 2008
    #1
    1. Advertising

  2. Instead of using Response.Write statements, use a literal. A literal is
    designed to take HTML and output it raw. This way you can get the placement
    on the page correct as who knows where it will get displayed using a
    Response.Write statement since that's not very conducive to event-driven
    environments.

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - Expression

    "kurt sune" <> wrote in message
    news:...
    > Hello, I have a weird problem, I hope someone can explain this for me.
    >
    > I have a webpage using masterpage.
    > In it I create a popup window using this code:
    > Dim js As String = "<script language=javascript>"
    >
    > js &= "var newWin = window.showModalDialog('InkommetVi.aspx"
    >
    > js &= "',null,"
    >
    > js &= "'center:yes; resizable:yes;help:no;dialogHeight:600px;
    > dialogWidth:750px;edge: Raised;status: No;');"
    >
    > js &= "</script> "
    >
    > Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "InkommetV", js)
    >
    >
    >
    > The popup window gets displayed all right.
    >
    > The popup window has a close button declared thus:
    >
    > <asp:Button ID="btnClose" runat="server" Text="Close" />
    >
    > And in it's clickevent I try to close the window: Response.Write("<script
    > language='javascript'> {window.close();}</script>")
    >
    >
    >
    > It doesn't work.
    >
    > I have tried with these: (they work on pages not using masterpage)
    >
    > ClientScript.RegisterStartupScript(Me.GetType(), "cwin",
    > "window.close();")
    >
    > Response.Write("<script language='javascript'> {window.opener = 'x';
    > window.close();}</script>")
    >
    > Response.Write("<script language='javascript'> {window.opener = '';
    > window.close();}</script>")
    >
    > Response.Write("<script language='javascript'> {this.focus();self.opener =
    > this;self.close();}</script>")
    >
    > Response.Write("<script language='javascript'> {top.window.opener =
    > top;top.window.open('','_parent','');top.window.close();}</script>")
    >
    > Response.Write("<script language='javascript'>
    > {window.open('','_self');window.close();}</script>")
    >
    > Response.Write("<script language='javascript'> {window.opener = self;
    > window.close();}</script>")
    >
    > Dim sScript As String = "<SCRIPT language='javascript'> "
    >
    > sScript &= "window.close();"
    >
    > sScript &= "</SCRIPT>"
    >
    > Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "InkommetVi",
    > sScript)
    >
    >
    >
    > Neither of them works.
    >
    >
    >
    > What does work however is this code on the page:
    >
    > <script type="text/javascript">
    >
    > window.onunload=st;
    >
    > function st()
    >
    > {
    >
    > window.close();
    >
    > }
    >
    > </script>
    >
    > <input id="Button1" type="button" value="Close" onclick="st();" />
    >
    >
    >
    >
    >
    > Can anybody explain this to me?
    >
    >
    >
    > /k
    >
    >
    >
    >
    >
    >
    Mark Fitzpatrick, Aug 18, 2008
    #2
    1. Advertising

  3. kurt sune

    imransyed63

    Joined:
    May 16, 2006
    Messages:
    27
    In the <Head> section of 'InkommetVi.aspx"

    add

    <base target="_self">
    imransyed63, Aug 19, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Storr
    Replies:
    5
    Views:
    39,374
  2. Stan B
    Replies:
    9
    Views:
    528
    Stan B
    Oct 17, 2006
  3. Iñaki Baz Castillo
    Replies:
    7
    Views:
    843
    Iñaki Baz Castillo
    Jan 12, 2010
  4. Jonathan
    Replies:
    0
    Views:
    188
    Jonathan
    Jul 19, 2004
  5. Shang Wenbin

    close current window using window.close()

    Shang Wenbin, Sep 1, 2005, in forum: Javascript
    Replies:
    10
    Views:
    368
    Gérard Talbot
    Sep 2, 2005
Loading...

Share This Page