Solved

ASP.NET/VB: Using classes without codebehind

Posted on 2013-12-27
1
618 Views
Last Modified: 2013-12-30
How can I combine these two files into one aspx file with no codebehind file?

Code:
<%@ Page Title="xyz" Language="VB" AutoEventWireup="false" CodeFile="xyz.aspx.vb" Inherits="runme" %>

Open in new window

Code Behind:
Imports System.Web.Script.Serialization
Public Class runme
    Inherits System.Web.UI.Page
    Dim obj As ResultRows
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim data As String = "{""total_rows"":1,""offset"":0,""rows"":[ {""xyz"":""Hello World"",""key"":""abc""}]}"
        Dim jsd As New JavaScriptSerializer
        obj = jsd.Deserialize(Of ResultRows)(data)
        Response.Write(obj.rows(0).xyz)
    End Sub
End Class

Public Class ResultRows
    Public rows() As ResultRow
End Class

Public Class ResultRow
    Public xyz As String
End Class

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39745859
Over the course of a couple of days I tried various ways and was actually sure that it wouldn't be possible...

I must admit I don't know specifically why this works and other things I tried didn't but looking at the various error I received (and clicking 'view full compiler output') it seems it has to do with the order code is created from the mark-up.

Anyway, this works (on framework v4), without any external code-behind file:
<%@ Page Title="xyz" Language="VB" AutoEventWireup="false" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<html>
<body>
<%
    Dim obj As ResultRows
    Dim data As String = "{""total_rows"":1,""offset"":0,""rows"":[ {""xyz"":""Hello World"",""key"":""abc""}]}"
    Dim jsd As New JavaScriptSerializer
    obj = jsd.Deserialize(Of ResultRows)(data)
    Response.Write(obj.rows(0).xyz)
%>
</body>
</html>

<script runat="server">
Public Class ResultRows
    Public rows() As ResultRow
End Class

Public Class ResultRow
    Public xyz As String
End Class
</script>

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now