ASP .NET vs. ASP

G

Guest

Hi all,

I have been thinking for long long time that how to create VB style class
in ASP .NET page. Below I am writing code written in normal ASP that I want
to convert to ASP .NET. I need your help for how to convert it. Please follow
the code below

----------------------------------------------------------------
[[[[[[[[[[[[[[[[[TestClass.asp]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
----------------------------------------------------------------
<%
Class TestClass

Sub JustPrint()
%>
<p>Hi this is just the test print</p>
<%
End Sub

Sub OtherPrint()
%>
<p>Hi this is another print</p>
<%
End Sub

End Class
%>

----------------------------------------------------------------
[[[[[[[[[[[[[[[[[Main.asp]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
----------------------------------------------------------------
<%@ Lauguage="VBSCRIPT"%>
<!--#include file="TestClass.asp"-->
<%
'Creating the class object
Dim clsObj
set clsObj = New TestClass

Dim requestedVal
requestedVal = Request.QueryString("type")

Select Case requestedVal
case 'other':
clsObj.OtherPrint
case else:
clsObj.TestPrint
End Select
%>


I think the above sample program is very simple. How can I convert the above
program with the same sort of flow control into ASP .NET.

My another question is "Can I still use #include directive in ASP .NET? I
want to break my HTML page into HEADER, SIDE MENU and FOOTER parts"

Your help will be appreciated
 
L

Lucas Tam

I think the above sample program is very simple. How can I convert the
above program with the same sort of flow control into ASP .NET.

You need to change the way you think. ASP.NET is TOTALLY different from
ASP. Flow control for the most part does not exist.

A simple solution to your problem is to place a Label control on the
page.

Then, call:

If SomeCondition Then
JustPrint()
Else
OtherPrint()
End If

JustPrint() would look like:

Private Sub JustPrint()
lblTest.text = "Hi this is just the test print"
End Sub

Private OtherPrint()
lblTest.text = "Hi this is another print"
End Sub

So as you can see... ASP.NET is VERY different from ASP.

My another question is "Can I still use #include directive in ASP
.NET? I want to break my HTML page into HEADER, SIDE MENU and FOOTER
parts"

No, there is no include.

You'll need to use a templating solution like ASP masterpages.
 
G

Guest

Why would somebody will then use ASP .NET instead of ASP if ASP style flow
control does not exists. I strictly wanted to have ASP style flow control.
Isn't there any other way?

Your help will be appreciated
 
L

Lucas Tam

Why would somebody will then use ASP .NET instead of ASP if ASP style
flow control does not exists. I strictly wanted to have ASP style flow
control. Isn't there any other way?

Your help will be appreciated

You have much to learn...

Because ASP flow control is MESSY. With ASP.NET you can do everything ASP
can and much much more. One thing you have to understand about ASP.NET is
the separation of display and logic. You no longer mix and match logic
(i.e. flow control). In ASP.NET you can replicate flow controls with many
cleaner techniques.

I suggest you check out the .NET tutorials which are available on several
sites like 4guysfromrolla.com.
 
G

Guest

Thanks Lucas once more.

If this is the case, then as far as I know every object, e.g, <asp:Checkbox
runat=server />, has to have a distinct name in ASP .NET.


I have an array of checkboxes in an asp page, this is how it will be coded
in ASP page

<input type="checkbox" name="checkbox" id="checkboxes" value="0">
<input type="checkbox" name="checkbox" id="checkboxes" value="0">
<input type="checkbox" name="checkbox" id="checkboxes" value="0">

When I retreive the value in ASP, it will be done like

<%
dim checkboxes
For I=0 to Request.Form("checkbox").length
Response.Write Request.Form("checkbox")(I)
Next

%>


How can I achieve the same effect in ASP .NET but as far as names are
concerned it has to be distinct. In my ASPX .NET page can I code like

<asp:checkbox id="checkbox" runat=server value=0 />
<asp:checkbox id="checkbox" runat=server value=0 />
<asp:checkbox id="checkbox" runat=server value=0 />
<asp:checkbox id="checkbox" runat=server value=0 />

I think this will be invalid. I eventually have to code like to give each
checkbox as a distinct name/id which will later be used for reference
purposes in ASPX.vb code

<asp:checkbox id="checkbox1" runat=server value=0 />
<asp:checkbox id="checkbox2" runat=server value=0 />
<asp:checkbox id="checkbox3" runat=server value=0 />
<asp:checkbox id="checkbox4" runat=server value=0 />


My question is how can i achieve the ASP style of scenario in ASP .NET page.

Small piece of code will definitely be helpful.

Thanks
Mohit
 
H

Hans Kesting

Lucas said:
No, there is no include.

You'll need to use a templating solution like ASP masterpages.

Or use Web User Controls for header, side menu, footer etc.

Hans Kesting
 
L

Lau Lei Cheong

I'll recommand you use asp:CheckBoxList instead.
You can check the control's status by checkboxlist1.Items.Selected =
true/false.
 
G

Guest

I don't why I find Web user Control so difficult.

I think I have to work bit hard to under stand ASP .NET concept.

Hmmm!!! Giving bit of thought, web development with ASP .NET, according to
me, will take the longest time as compared to ASP.

Same is the case with ASP and PHP/PERL

I have recently been invovled with ASP and PHP web development, but some how
ASP .NET work flow is very very different and difficult as well.
 
H

Hans Kesting

Mohit said:
I don't why I find Web user Control so difficult.

I think I have to work bit hard to under stand ASP .NET concept.

Hmmm!!! Giving bit of thought, web development with ASP .NET,
according to me, will take the longest time as compared to ASP.

Same is the case with ASP and PHP/PERL

I have recently been invovled with ASP and PHP web development, but
some how ASP .NET work flow is very very different and difficult as
well.

ASP (old-style) and PHP both mix text for output (usually HTML) and code.
When executing the code you build some text file that happens to be in HTML format.

With ASP.Net you build an object tree that eventually renders as HTML.

It's quite a step, but it's worth it (I think).

Hans Kesting
 
L

Lucas Tam

Hmmm!!! Giving bit of thought, web development with ASP .NET,
according to me, will take the longest time as compared to ASP.

Yes, initial development will take longer with ASP, however, maintenance
and scalibility is greater with ASP.NET.

It's much easier to fix ASP.NET code than it is to fix ASP code.
I have recently been invovled with ASP and PHP web development, but
some how ASP .NET work flow is very very different and difficult as
well.

ASP.NET is a totally different beast. There's no other web development
language quite like it. It'll take a while for you to get your head around
all the subtleties, but once you do, I'm sure you won't regret learning
ASP.NET.
 
L

Lucas Tam

How can I achieve the same effect in ASP .NET but as far as names are
concerned it has to be distinct. In my ASPX .NET page can I code like

<asp:checkbox id="checkbox" runat=server value=0 />
<asp:checkbox id="checkbox" runat=server value=0 />
<asp:checkbox id="checkbox" runat=server value=0 />
<asp:checkbox id="checkbox" runat=server value=0 />

I think this will be invalid. I eventually have to code like to give
each checkbox as a distinct name/id which will later be used for
reference purposes in ASPX.vb code

<asp:checkbox id="checkbox1" runat=server value=0 />
<asp:checkbox id="checkbox2" runat=server value=0 />
<asp:checkbox id="checkbox3" runat=server value=0 />
<asp:checkbox id="checkbox4" runat=server value=0 />


My question is how can i achieve the ASP style of scenario in ASP .NET
page.

So basically what you want to do here is to create dynamic checkboxes.

As Lau Lei Cheong states in the next message, there is the checkbox list
class which can dynamically create an array of checkboxes. However,
let's assume you're using a textbox which has no list class (so life
isn't as easy).

In this case, you need to put a placeholder on the webpage. A
placeholder is a programmatic reference to a location on a webpage. What
you would do is add TextBox controls into a Placeholder control via
code:

Dim Box as TextBox

For i as integer = 1 to 10
Box = new TextBox 'Creates a new instance of a textbox
Box.id = txtBox & i 'Gives the box an ID <-not really needed...
'but good to have to find the box later
PlaceHolder.controls.add(Box) 'Adds the box to the PH
Next

To retreive the textbox, there are multiple ways.

1. Loop through Page.Controls. Page.controls contains ALL the controls
on a page. So even if you did not know the name of a control, you can
find it programmatically through Page.Controls.

2. Use the Control.FindControl Method. FindControl finds a control based
on an ID. For example you wish to return the text typed inside txtBox10
that was created programmatically:

MyText = Ctype(FindControl("txtBox10"), TextBox).Text

3. You can request.form the values directly too... but this isn't
recommended.

The above example was if the textboxes were created programmically. If
they were just placed on the page (i.e. Via the Visual Designer in
VS.NET), you can just refer to them directly via the ID/Variable name.
 
G

Guest

Lucas Tam said:
Yes, initial development will take longer with ASP, however, maintenance
and scalibility is greater with ASP.NET.

Yeah!!! I strongly agree with you. It is all about experience. For a newbie
like me in ASP .NET, and an expert in PHP or ASP, initially it is very hard
to grasp the idea of ASP .NET because in PHP or ASP we can merge ASP code
with HTML code.

One good thing that I liked about ASP .NET is object oriented concept.
However, if you are aware of PHP 5, it has also introduced OO concept and to
me, I think, web development will be atleast 10 times faster in PHP than
either ASP or ASP .NET. I am not contradicting or criticising anybody. It is
just a matter of experience and learning.

Moving to any new technology is always painful in the begining but when one
start getting hold of subtleties of that, things become very interesting.

I think in terms of POSTBACK operations, ASP .NET is really ahead. Atleast
it saves some time of mine to refill the values programmatically in PHP or
ASP. Alteast microsoft this time has done good job (I think) to relieve some
pressure from programmers.

There are lot of things to learn in ASP .NET then in any other technology.
It's much easier to fix ASP.NET code than it is to fix ASP code.

I am really not sure about it. However, I know one thing is that it is much
difficult to learn ASP .NET. Mainly because of single form. Normally in an
HTML page, we can have multiple forms where element values can be exchanged
between different forms. But in ASP .NET there is only 1 form concept and I
am still very confused that how to use multiple form concept.

Secondly, the concept of RegisterScriptBlock ( I think) for inserting
javascript. I am still not sure why to use it.

Consider an example below

<asp:Button runat=server id=Button1 onClick="testClick()" />

<SCRIPT LANGUAGE="javascript">
function testClick() {
:
}
</SCRIPT>

When I put above code in aspx page, server reports me an error about
"testClick()" method don't found or something like that.

But when in my .aspx.vb file, I put this statement

Me.Button1.RegisterScriptBlock(.....,"testClick()"), everything works fine.

So I think there are still lot of things to work on for me and I don't know
how long it will take to fully understand the concept.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top