1

I've embeded the following server side code within <script> tag.

<%  Dim dataTable As DataTable = cTab.getTabs(Session("UserID"))
    If (dataTable.Rows.Count > 0) Then
       For i As Int16 = 0 To dataTable.Rows.Count%>
       {
           contentEl: 'tab'+'<%dataTable.Rows(0)("TabID").ToString()%>', 
           title: '<%dataTable.Rows(0)("TabName").ToString()%>',
           closable: false,
           autoScroll: true
           },
        <% Next
    End If %>

But it is not returning the desired results due to syntax problems. How can I write it correctly?

1
  • could u please explain what do u want to do? and what syntax errors u are facing Commented Feb 17, 2010 at 6:12

3 Answers 3

2

You've only given us a portion of the entire javascript, so we can't analyze what the surrounding script looks like in order to look for syntax issues. The snippet you've given will just start with an opening curly brace, which is not valid just standing by itself. What's preceeding it?

Besides that, if you want to output a string to the script, you need to do it using Response.Write or using the <%= %> shortcut. So for one, you need to do:

   contentEl: 'tab'+'<%= dataTable.Rows(0)("TabID").ToString() %>', 
   title: '<%= dataTable.Rows(0)("TabName").ToString() %>',

(Notice the = signs).

Sign up to request clarification or add additional context in comments.

Comments

1

Without seeing the surrounding code....

Looking at the loop each item is generated with a trailing comma (,) this means that there will be an extra comma at the end which is not valid is some browsers.

Invalid Example

var myObjArr = [
  {
    contentEl: 'tab'+'123', 
    title: 'name123',
    closable: false,
    autoScroll: true
  },
  {
    contentEl: 'tab'+'456', 
    title: 'name456',
    closable: false,
    autoScroll: true
  },
];

Valid Example

var myObjArr = [
  {
    contentEl: 'tab'+'123', 
    title: 'name123',
    closable: false,
    autoScroll: true
  },
  {
    contentEl: 'tab'+'456', 
    title: 'name456',
    closable: false,
    autoScroll: true
  }
];

Note the second sample has no extra comma (,).

Comments

0

Assuming your loop is working you probably don't want to have the same value every time. I think you might want to use i instead of 0. That is just a wild guess though since I really can't tell if the loop should work or not.

contentEl: 'tab'+'<%= dataTable.Rows(i)("TabID").ToString()%>', 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.