[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
Quote:
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
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 :eek:.
Mehdhi you still prowl this board?
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.
Re: [Resolved] <% %> vs <script runat=server>
Yes I'm still here, and how did he bring you back, is he a wizard?
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.
Quote:
Yes I'm still here, and how did he bring you back, is he a wizard?
Lots of death threats
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.
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. :D
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.