Results 1 to 8 of 8

Thread: [Resolved] <% %> vs <script runat=server>

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Resolved [Resolved] <% %> vs <script runat=server>

    I finally decided to migrate from ASP to .NET, so you will see me here quite often.

    Anyway, what I'm trying to understand is the difference between the
    <% %> tags vs <script runat=server>

    It seems like both methods work identical. Furthermore, when I create a function in <script> tags I can then access it in the <% %>

    What is the difference? Which one should I be using?

    Thank you!

    ------------------

    After doing a few google searches i found this at
    velocityreviews.com/forums

    Craig Deelsnyder

    Posts: n/a

    Default Re: <script language="vb" runat=server> versus <% %>
    [email protected] wrote:

    > Pardon the newbie question...
    >
    > What's the difference between (asp.net)VB code inside one versus the
    > other. And why have both?

    There is no difference, assuming your app's default language (set in the
    page or web.config) is set to VB. The second one is shorthand for the
    first, it'll assume the default language of your app (or page)....I
    recommend using the former though for clarity as the latter was more of
    an ASP legacy notation, which I don't know if it's frowned upon using
    now....

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Last edited by invitro; Jul 8th, 2006 at 03:59 PM. Reason: Spelling, format, and a resolution yay!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: [Resolved] <% %> vs <script runat=server>

    Alek, ASP.Net was designed to be an object oriented language and move away from the scripting side like classic asp. The use of script Tag within your html code is never a good idea. You should use a seperate .vb or .cs class (Code Behind) to keep your presentation and application logic seperate. It becomes million time easier to maintain your application in the long run. Trust me on that.

    Also if you use Code behind your code will get compiled into a dll rather then Interpreted if you use <% %> tag.


    Well thats all for today, you have brought me back after nearly two years to this board .


    Mehdhi you still prowl this board?
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3
    Fanatic Member Valleysboy1978's Avatar
    Join Date
    Nov 2004
    Location
    Planet Xeoroaniar CC Posts:1,928,453,459,361
    Posts
    770

    Re: [Resolved] <% %> vs <script runat=server>

    <% %> - This is a method call and can activate Subs, Functions or Events
    <runat="server"> - This is so that a form object (such as a textbox, button) will have associated server-side events.
    Life is one big rock tune

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [Resolved] <% %> vs <script runat=server>

    Yes I'm still here, and how did he bring you back, is he a wizard?

  5. #5

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Smile Re: [Resolved] <% %> vs <script runat=server>

    What I am doing is a Database class for my own website. Everything happens behind the scenes in a CS file, I only use <% to call and create objects and then use them on my pages.

    This is just a basic sample of how I am doing this.

    Code:
    <% 
    Connection.Database objDatabase = new Connection.Database();
    SqlDataReader sqlReader = null;
    sqlReader = objDatabase.GetAllUsers();
    
    if(sqlReader != null)
    {
        while(sqlReader.Read())
        {
            Response.Write(sqlReader[0]);
        }
    }
    
    sqlReader.Close();
    objDatabase.CloseConnection();
    
    
    %>
    Connection is a namespace and Database is the class. The Database class contains functions that call stored procedures, which I then use in my ASPX website.

    Judging by your response I think I'm on the right track.

    Thanks a lot for your help guys.

    Yes I'm still here, and how did he bring you back, is he a wizard?
    Lots of death threats
    Last edited by invitro; Jul 12th, 2006 at 03:52 PM. Reason: My horrid spelling
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [Resolved] <% %> vs <script runat=server>

    I wouldn't say you're on the right track. You're still sticking to the old ASP 3.0 style of coding. You can use the Page Load event to create the objects and use them as you will.

    Want an ASP.NET tutorial?

    By the way, google takes about 1 second to search the Internet because it stores its results on a large arrayed network after hours of crawling web servers.

  7. #7

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Re: [Resolved] <% %> vs <script runat=server>

    A tutorial would be awsome. I need to get out of the habbit of coding in ASP and move towards ASP .NET.

    What I don't get is how I'm suppose to manipulate that code in a CS file and then pass it to the aspx page without actually manipulating the data in the aspx file. I hope the tutorial answers that.

    Again thanks for the help.

    PS: I knew someone was going to spring the google trap.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [Resolved] <% %> vs <script runat=server>

    This is the one I link most:

    http://samples.gotdotnet.com/quickstart/aspplus/

    And remember, when learning ASP.NET, let go of the old Classic ASP habits. They are now bad. Most of them anyways.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width