Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET/VB: Using classes without codebehind

Posted on 2013-12-27
1
Medium Priority
?
643 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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