JavaScript Error

Last post 07-07-2008 3:18 AM by Maulik Patel. 7 replies.

Sort Posts:

  • JavaScript Error

    07-06-2008, 12:01 PM
    • Loading...
    • xzin
    • Joined on 06-30-2008, 7:48 PM
    • Posts 11
    Hi guys .. It's me again!
    I know my problem may seem to some of you a peice of cake .. but not for Begginers like myself!
    I'm having an error when writing this code in my web application
      <%@ Page Language="VB" Title="Start" Theme="Silver" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">                  Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)       

     Response.Write("<Script language=""javaScript""> window.open('','_parent','');window.close();</script>")

     End Sub

    </script> 



    In the Timer1_Tick, four errors showing (1. Cannot switch views , 2.Statement Cannot appear within a Method body End of Method assumed.3.String Constants must end with double quote.4.Statement Cannot appear ...etc
    I've been searching for a solution for this error the whole day ! i wasn't lucky
    Any Help my friends would be apperciated 

  • Re: JavaScript Error

    07-06-2008, 1:33 PM

    Response.Write("<Script language='javaScript'> window.open('','_parent','');window.close();</script>")

  • Re: JavaScript Error

    07-06-2008, 2:50 PM
    • Loading...
    • pradeep7n
    • Joined on 10-24-2007, 6:07 AM
    • Coimbatore, India
    • Posts 210
    Response.Write("<Script language='javascript' type='text/javascript'>window.open('','_parent','');window.close();</script>")
     
    Please remember to click "Mark as Answer" on this post if it helped you.
    Happy Coding Yes
    Pradeep
  • Re: JavaScript Error

    07-06-2008, 3:27 PM
    • Loading...
    • gunteman
    • Joined on 07-11-2007, 12:57 PM
    • Norrköping, Sweden
    • Posts 2,324

     You should not use Response.Write at all. If you're using ASP.NET AJAX, then ScriptManager.RegisterClientScriptBlock is what you should use.

    -- "Mark As Answer" if my reply helped you --
  • Re: JavaScript Error

    07-06-2008, 4:01 PM
    • Loading...
    • xzin
    • Joined on 06-30-2008, 7:48 PM
    • Posts 11

    am still having the same error!!

    plz notice that am writing my code in the Source area .. not the ( .VB) area

    i wish i can write this code in the VB area .. but there i only see the PageEvents .. i can't see any other event of my controls like the Timer in this case..is there anyway that i can get the Timer event in .vb area .. ?

  • Re: JavaScript Error

    07-06-2008, 10:59 PM

    Ok...you're using the timer and thus asp.net AJAX. You can't (and NEVER should for registering js) use Response.Write. Do this:

    ClientScript.RegisterClientScriptBlock(TypeOf(Page), "unique_key" & DateTime.Now, "window.open('', '_parent', '');", True)

    If you wish to have the script loaded only once, make the second param constant (that is, remove the DateTime.Now).

  • Re: JavaScript Error

    07-07-2008, 12:13 AM
    • Loading...
    • xzin
    • Joined on 06-30-2008, 7:48 PM
    • Posts 11

    the error is no longer there .

    the timer fires but it does not execute my script window.open(' ','_parent',' '); which is supposed to close the parent winodw without the prompt message.

    here's what i wrote:

    ClientScript.RegisterClientScriptBlock(Page.GetType, "unique_key", "window.open('', '_parent', '');", True)

    any help would be appreciated my friends :)

  • Re: JavaScript Error

    07-07-2008, 3:18 AM
    Answer
    • Loading...
    • Maulik Patel
    • Joined on 12-21-2007, 1:48 AM
    • Ahmedabad
    • Posts 273

    If you are using AJAX timer than

    ScriptManager.RegisterStartupScript(Page, Page.GetType, "unique_key", "window.open('','_parent','');window.close();", True) 

    Maulik Patel
    MCTS, Software Engineer

    Don't forget to click "Mark as Answer" on the post that helped you. This will give you point and help readers to know which post solved your issue and make their search easy.
Page 1 of 1 (8 items)
Microsoft Communities
Page view counter