• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

manipulate html in asp server side

I am trying to move some difficult html manipulation form javascript to the server using asp.
Is there anything I can do to take the following content and then load it into an xml or other object and manipulate, add a row, change field names, etc.?

Maybe is it  possible to run javascript on the server?

I am using an ajax call to send the table html to the asp page and returning the changed
html table to the div wrapper

The goal is to move away from jquery and javascript on the client to an easier to code server based solution.  The table is a multirow that needs have delete and add row capabilities.
Ideally, if I could take the html, convert it to xml then use dom then back.  Or just
make the html fit into the xml dom?
0
KeithMcElroy
Asked:
KeithMcElroy
  • 3
1 Solution
 
KeithMcElroyAuthor Commented:
If I could do something like this and then manipulate the html using dom methods...



h = Request("datagridHTML")


sXml = h

      Dim oXml
      Set oXml = CreateObject("Microsoft.XMLDOM")
      oXml.async = false
      oXml.loadxml sXml
      set loadXStr = oXml

response.write h
0
 
KeithMcElroyAuthor Commented:
And more, if i could...


h = Request("datagridHTML")


sXml =     h  

      Dim oXml
      Set oXml = CreateObject("Microsoft.XMLDOM")
      oXml.async = false
      oXml.loadxml sXml
      set loadXStr = oXml
      
      set newtr = oXml.SelectNodes("//TBODY/TR").cloneNode(true)
            
      set parent = newtr.parentNode
      parent.appendnode(newtr)
            
      

response.write h
0
 
Scott Fell, EE MVEDeveloperCommented:
I undertand where you are coming from. You have a good feeling for asp and vb and javascript is not as intuitive from the start.   If you are going to manipulate things in the browser, it (the page loading) is really much faster to use javascript/jquery.  

With asp, you can run javascript (jscript) server side and you can create your html dynamically.  However, it can take up a lot of processor/memory on the server and slow loading times compared to getting the data to the browser and let javascript quickly move the dom stuff around.

Just as a test check out this project https://github.com/douglascrockford/JSON-js  Try running it as client side javascriipt.  Then run it serverside

<script language="JScript" runat="server" src='path/to/json2.js'></script>
http://stackoverflow.com/questions/1019223/any-good-libraries-for-parsing-json-in-classic-asp
<%@Language="VBScript" %>
<%
Option Explicit
%>

<script language="JScript" runat="server" src='path/to/json2.js'></script>

<%

Dim myJSON
myJSON = Request.Form("myJSON") // "[ 1, 2, 3 ]"
Set myJSON = JSON.parse(myJSON) // [1,2,3]
Response.Write(myJSON)          // 1,2,3
Response.Write(myJSON.[0])      // 1
Response.Write(myJSON.[1])      // 2
Response.Write(myJSON.[2])      // 3
%>

Open in new window

In the same manner you can run other javascript serverside in classic asp.  However, notice how much slower it runs.  I have tried the same with http://code.google.com/p/crypto-js/

It did take me some time to embrace javascript/jquery for the same reason.   But for what it sounds like you want to do, client side scripting is the way to go.
w3schools.com and www.codecademy.com are good places to get started.
0
 
KeithMcElroyAuthor Commented:
Thank you for the help and easy to digest commentary.
Really helps alot.  I am revisiting jquery for this and will look into running on the server
for when it might be needed down the road.
All good.  Thanks a mil!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now