Solved

ASP.NET/VB: Using classes without codebehind

Posted on 2013-12-27
1
632 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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.…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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