Single Page ASPX Problem with <Script> Tag

ajax , asp.net , java , javascript Syria
  • 12 years ago

    I am currently moving my aspx pages from code behind pages over to single aspx page.  I am having trouble with the <Script> tag that is inside the <Script runat="server"> tag.  Here is a sample of the code that is giving me grief:

    <script runat="server">

    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TimerLogOff.Tick

    Response.Write("<script language=""vbscript"" type=""text/vbscript"">Window.close()</script>")

    End Sub

    </script>

    I hope it's something simple that I'm missing.  Thanks JM40

  • 12 years ago

    Not sure if you can call vbscript within a dotnet page.

    Try doing it using javascript. 

    <script runat="server">

    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TimerLogOff.Tick

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

    End Sub

    </script>

     

  • 12 years ago

    Thanks but it is still a problem. It seems to have a problem with the second set of <Script> tags regardless of VB or Java Script.  Do I need to stick with the 2 page model and keep the code behinds to accomplish what I want? 

  • 12 years ago

    When I tested it I was using code behind page. But I should have seen that there would be a problem with having another </script> tag within one. I also see you are using ajax and the timer control. So you have two problems one is inoder to close a clients browser window you must use client side code. Problem two is that you can not call javascript code with the ajax timer control.

    So you can do one of two things. You can move this two a code behind page so when the timer control does a page reload you can use the response.write to write the javascript to close the window. Or you can forget about using the ajax timer control and just use javascript to do the same thing.

    <head runat="server">

    <title>Untitled Page</title>

     

    <script type="text/javascript">

     function pageLoad()

    {

    setInterval('pageClose()', 5000); //Page will close in 5 seconds.

    }

    function pageClose()

    {

    window.close();

    }

    </script>

    </head>

     I think you are going to find out that if you want to use ajax you are going to need to know some javascript.

  • 12 years ago

     

  • 12 years ago

     

  • 12 years ago

     

  • 12 years ago

     

  • 12 years ago

     

     
  • 12 years ago

     

     
  • 12 years ago

     

      
  • 12 years ago

    Yes I am using ajax and I am brushing up on my javascript.  I'll say it again, the real problem is having the <Script> tag inside the <Script> section of the page.

    I did come up with a work around.  I have a class that has some functions in it.  I added this function to it:

    Public Shared Function JavaReturn(ByVal SomeJavaString As String) As String

      Return "<script language='javascript' type='text/javascript'>" & SomeJavaString & "</script>"

    End Function

    I now am able to within my <Script> tags be able to run some basic java like below and not: have issues with the <Script> tags.

    <script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

        Response.Write(clsFunctions.JavaReturn("window.open('','_self','');window.close();"))
    End Sub

    </script>

    Although this works if I don't need to use the function I would rather not.  Any thoughts?
    Thanks

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup