Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2004, 06:28 AM
Authorized User
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default vb script is not working

Hi,
VB script written inside the aspx file is not working.
Here is the code.
<%@ import namespace= "system.data.oledb"%>
<%@ Import namespace="System.Data"%>
<%@ Page Language="vb" AutoEventWireup="false" src="aspnet101.aspx.vb" Inherits="aspnet101"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>aspnet101</title>
        <script language="VB" runat="server">
    Sub Page_Load(Source as Object, E as EventArgs)
        Dim count As Integer
        Dim fldName As String
        Dim strConn As String = "Provider=MSDAORA.1;Password=demo;User ID=demo;Data Source=tst1;"
        Dim MySQL As String = "Select * from project"
        Dim MyConn As New OleDbConnection(strConn)
        Dim objDR As OleDbDataReader
        Dim Cmd As New OleDbCommand(MySQL, MyConn)
        MyConn.Open()
        Response.Write("jkjsdasdas")
        Try
            objDR = Cmd.ExecuteReader(system.data.CommandBehavior.Clos eConnection)
            For count = 0 To objDR.FieldCount - 1
                lstFields.Items.Add(objDR.GetName(count))
            Next count
        Catch ex As Exception
            Response.Write(ex.Message)
        Finally
            MyConn.Close()
        End Try
end sub

        </script>
        <meta name="vs_showGrid" content="True">
        <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
        <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:ListBox id="lstFields" Runat="server" />
        </form>
    </body>
</HTML>

If same code placed inside aspx.vb file, it works fine. Can anyone give solution.

I'm using VS.NET 1.0.

Thanks,
Apry

 
Old April 27th, 2004, 06:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Apry,

I don't see any VBScript in your page. Or are you referring to VB.NET as the page language?

Anyway, I think you should fix your page directive. Right now, it tells the compiler to look for the source in an external file. Change it to this:

<%@ Page Language="vb" AutoEventWireup="false" %>

You could also throw in a ClassName, although I don't know if that's required:

<%@ Page Language="vb" AutoEventWireup="false" ClassName="MyClass"%>

If this doesn't help, can you define "not working"? Do you get an error? If so, what error?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Eleutheria by Lenny Kravitz (Track 11 from the album: Are You Gonna Go My Way) What's This?
 
Old April 28th, 2004, 12:24 AM
Authorized User
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imran,
Thanks for the prompt reply.
I changed the page directive and now it's working fine.
I have one more doubt. If I'm writting business logic as .aspx.vb file and front end validations inside .aspx file using VB script. In this case how do I specify the page directive.
If I use following code in aspx file
<%@ Page Language="vb" AutoEventWireup="false" codebehind="WebForm1.aspx.vb" %>, then VB script will not work.
How do I solve this problem. Pls help me.

Thanks,
Apry

 
Old April 28th, 2004, 12:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Apry,

I don't think you can. First of all, you're not using VB Script; your are using Visual Basic .NET, or VB.NET. VBScript belongs to "classic" ASP, client side pages and other scripting environments. ASP.NET uses a real and compiled language, and no longer script.

This is also the reason that you cannot mix code in the .ASPX page and the .ASPX.VB page. When the page is requested, it is compiled on the fly (if it wasn't compiled already). To know how and what should be compiled, the page directive is checked.
When there is a src attribute, the .vb is compiled, otherwise the in-line code is used. In ASP.NET 1.0 and 1.1 it's not possible to have code for one class (your page) in two files to be compiled together.

The next version of ASP.NET will have a feature called Partial Classes, that does allow you to define classes at multiple locations. This way, you could have stuff in the .aspx page and in the Code Behind page.

While you're waiting for the next version, you could decide to move your business logic to a Class Library. You can create a DLL with your business logic classes that is accessed from the ASPX pages.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.


 
Old April 28th, 2004, 04:46 AM
Authorized User
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
Creating a DLL is a wonderful idea. I tried the same and it works fine.
Here my problem is performance. I have to do lot of validations at client side in my application. For example showing the sum of two text box values, check whteher the ‘from’ date is grater than the ‘To’ date etc. So if I write code for each validation in .vb file, will affect the performance of my application. Can you suggest some better method.

Regards,
Apry

 
Old April 28th, 2004, 05:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Apry,

Performance wise there is not much of a difference between server side code that is placed in-line (e.g. in the .aspx page) or that is placed in a separate .vb file. In both cases, when the page is first hit, the code is compiled on the fly, and the results are saved to disk for future use. You can avoid this initial performance hit by compiling your entire application to a DLL using Code Behind in Visual Studio, or by creating a separate Class Library with your business logic.

What may make a difference in terms of performance is using validators that run at the client. These controls will submit JavaScript that can validate things at the client, and thus saving you a round-trip and server processing time to validate the user input. However, from a security perspective, you should still validate the input at the server as well. But because the data is likely to arrive in a good state when it has been checked at the client, you save yourself a few round-trips to get the data in the required format.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Homesick by The Cure (Track 11 from the album: Disintegration) What's This?






Similar Threads
Thread Thread Starter Forum Replies Last Post
IE7 script not working on linux server luminus BOOK: CSS Instant Results 9 February 1st, 2016 07:35 AM
script not working in mozilla, but works in IE grobar Javascript 1 April 9th, 2008 03:51 AM
Client Side Script Not Working sramesh ASP.NET 2.0 Basics 3 August 2nd, 2007 03:56 PM
script not working in mozilla but works in IE grobar Javascript How-To 0 May 26th, 2005 06:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.