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
Solved

ASP.NET/VB: Using classes without codebehind

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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