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
    • Member
      2 point Member
    • xzin
    • Member since 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
    • All-Star
      29,873 point All-Star
    • HeartattacK
    • Member since 01-08-2007, 12:53 PM
    • Dhaka, Bangladesh
    • Posts 3,236
    • Moderator
      TrustedFriends-MVPs

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

    All that glitters is gold-
    Only shooting stars break the mold.

    Read my blog: www.heartysoft.com

    Tell me what tutorials / articles / videos you want to see on my site.
  • Re: JavaScript Error

    07-06-2008, 2:50 PM
    • Participant
      1,244 point Participant
    • pradeep7n
    • Member since 10-24-2007, 6:07 AM
    • Coimbatore, India
    • Posts 212
    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
    • All-Star
      21,582 point All-Star
    • gunteman
    • Member since 07-11-2007, 12:57 PM
    • Norrköping, Sweden
    • Posts 3,169

     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
    • Member
      2 point Member
    • xzin
    • Member since 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
    • All-Star
      29,873 point All-Star
    • HeartattacK
    • Member since 01-08-2007, 12:53 PM
    • Dhaka, Bangladesh
    • Posts 3,236
    • Moderator
      TrustedFriends-MVPs

    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).

    All that glitters is gold-
    Only shooting stars break the mold.

    Read my blog: www.heartysoft.com

    Tell me what tutorials / articles / videos you want to see on my site.
  • Re: JavaScript Error

    07-07-2008, 12:13 AM
    • Member
      2 point Member
    • xzin
    • Member since 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
    • Contributor
      2,342 point Contributor
    • Maulik Patel
    • Member since 12-21-2007, 1:48 AM
    • Ahmedabad
    • Posts 333

    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)