Solved

ASP.NET/VB: Using classes without codebehind

Posted on 2013-12-27
1
630 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.net Open video relating to control 2 29
vb.net Configuration, settings file location? 8 42
Find date of 2nd Thursday of each month 3 32
Need help with a query 3 36
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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